diff --git a/README.md b/README.md index d1d1702..5adce8b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ npm run dev Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. +By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`. + ## Deploying to the web @@ -47,6 +49,7 @@ npm install -g now Then, from within your project folder: ```bash +cd public now ``` diff --git a/package.json b/package.json index 48087d8..9c913cd 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,12 @@ "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", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-svelte": "^5.0.3", - "rollup-plugin-terser": "^4.0.4", + "rollup-plugin-terser": "^5.1.2", "svelte": "^3.0.0" }, "dependencies": { @@ -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..eb2eedd --- /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'], shell: true }); + } + } +}; diff --git a/src/App.svelte b/src/App.svelte index 0fbce2a..601206c 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -5,6 +5,7 @@