From 7b0bb3279dd1bc0fb5e60eccc65a3422395c8f62 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 16 Nov 2019 12:35:34 -0500 Subject: [PATCH] remove start:dev, put serve plugin in config file --- package.json | 3 +-- rollup.config.js | 22 +++++++++++++++++++--- rollup_start_dev.js | 12 ------------ 3 files changed, 20 insertions(+), 17 deletions(-) delete mode 100644 rollup_start_dev.js 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 }); - } - } -};