From 66cb32c6fc81ef171ec571a71a5adc46e12c944e Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 23 Oct 2019 09:43:45 -0400 Subject: [PATCH] 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 --- package.json | 4 +--- rollup.config.js | 5 +++++ rollup_start_dev.js | 12 ++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 rollup_start_dev.js diff --git a/package.json b/package.json index 48087d8..1ef0ea5 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/rollup.config.js b/rollup.config.js index e5b94ec..04755f3 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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'), diff --git a/rollup_start_dev.js b/rollup_start_dev.js new file mode 100644 index 0000000..228f8dc --- /dev/null +++ b/rollup_start_dev.js @@ -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'] }); + } + } +};