Skip to content

Commit

Permalink
don't start dev server until bundle is generated (sveltejs#73)
Browse files Browse the repository at this point in the history
* don't start dev server until bundle is generated (sveltejs#72)

* extract `npm run start:dev` spawn into separate file
  • Loading branch information
Conduitry authored Oct 23, 2019
1 parent 4e3a408 commit 66cb32c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "svelte-app",
"version": "1.0.0",
"devDependencies": {
"npm-run-all": "^4.1.5",
"rollup": "^1.12.0",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-livereload": "^1.0.0",
Expand All @@ -16,8 +15,7 @@
},
"scripts": {
"build": "rollup -c",
"autobuild": "rollup -c -w",
"dev": "run-p start:dev autobuild",
"dev": "rollup -c -w",
"start": "sirv public --single",
"start:dev": "sirv public --single --dev"
}
Expand Down
5 changes: 5 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import rollup_start_dev from './rollup_start_dev';

const production = !process.env.ROLLUP_WATCH;

Expand Down Expand Up @@ -36,6 +37,10 @@ export default {
}),
commonjs(),

// In dev mode, call `npm run start:dev` once
// the bundle has been generated
!production && rollup_start_dev,

// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),
Expand Down
12 changes: 12 additions & 0 deletions rollup_start_dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as child_process from 'child_process';

let running_dev_server = false;

export default {
writeBundle() {
if (!running_dev_server) {
running_dev_server = true;
child_process.spawn('npm', ['run', 'start:dev'], { stdio: ['ignore', 'inherit', 'inherit'] });
}
}
};

0 comments on commit 66cb32c

Please sign in to comment.