don't start dev server until bundle is generated (#73)

* don't start dev server until bundle is generated (#72)

* extract `npm run start:dev` spawn into separate file
This commit is contained in:
Conduitry 2019-10-23 09:43:45 -04:00 committed by GitHub
parent 4e3a4089b4
commit 66cb32c6fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View file

@ -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",
@ -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"
}

View file

@ -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;
@ -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'),

12
rollup_start_dev.js Normal file
View file

@ -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'] });
}
}
};