diff --git a/package.json b/package.json index 9c913cd..3b40276 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "scripts": { "build": "rollup -c", "dev": "rollup -c -w", - "start": "sirv public --single", - "start:dev": "sirv public --single --dev" + "start": "sirv public --single" } } diff --git a/rollup.config.js b/rollup.config.js index c11d174..b7efb84 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,7 +3,6 @@ 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; @@ -37,9 +36,9 @@ export default { }), commonjs(), - // In dev mode, call `npm run start:dev` once + // In dev mode, call `npm run start` once // the bundle has been generated - !production && rollup_start_dev, + !production && serve(), // Watch the `public` directory and refresh the // browser on changes when not in production @@ -53,3 +52,20 @@ export default { clearScreen: false } }; + +function serve() { + let started = false; + + return { + writeBundle() { + if (!started) { + started = true; + + require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { + stdio: ['ignore', 'inherit', 'inherit'], + shell: true + }); + } + } + }; +} \ No newline at end of file diff --git a/rollup_start_dev.js b/rollup_start_dev.js deleted file mode 100644 index eb2eedd..0000000 --- a/rollup_start_dev.js +++ /dev/null @@ -1,12 +0,0 @@ -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'], shell: true }); - } - } -};