From 2752c73ebb2fd68aea5ec35576dbeb2457a7d2ee Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 18 Feb 2018 17:24:12 -0500 Subject: [PATCH] -> v0.7.2 --- CHANGELOG.md | 5 +++ src/hmr-client.js => hmr-client.js | 2 -- package.json | 3 +- src/cli/dev.ts | 50 +++++++++++++++++------------- src/core/create_app.ts | 2 +- 5 files changed, 37 insertions(+), 25 deletions(-) rename src/hmr-client.js => hmr-client.js (94%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc1215..bd960ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # sapper changelog +## 0.7.2 + +* Add `hmr-client.js` to package +* Wait until first successful client build before creating service-worker.js + ## 0.7.1 * Add missing `tslib` dependency diff --git a/src/hmr-client.js b/hmr-client.js similarity index 94% rename from src/hmr-client.js rename to hmr-client.js index fa478b9..88938dc 100644 --- a/src/hmr-client.js +++ b/hmr-client.js @@ -1,7 +1,5 @@ let source; -console.log('!!!! hmr client'); - function check() { if (module.hot.status() === 'idle') { module.hot.check(true).then(modules => { diff --git a/package.json b/package.json index 16ef87b..7edd5df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sapper", - "version": "0.7.1", + "version": "0.7.2", "description": "Military-grade apps, engineered by Svelte", "main": "middleware.js", "bin": { @@ -12,6 +12,7 @@ "middleware.js", "runtime", "runtime.js", + "hmr-client.js", "webpack" ], "directories": { diff --git a/src/cli/dev.ts b/src/cli/dev.ts index 835911e..3f32e70 100644 --- a/src/cli/dev.ts +++ b/src/cli/dev.ts @@ -182,33 +182,41 @@ export default async function dev(src: string, dir: string) { }); }); - return create_serviceworker({ + create_serviceworker({ routes: create_routes({ src }), client_files, src }); + + watch_serviceworker(); } }); - if (compilers.serviceworker) { - compilers.serviceworker.plugin('invalid', (filename: string) => { - times.serviceworker_start = Date.now(); - }); + let watch_serviceworker = compilers.serviceworker + ? function() { + watch_serviceworker = noop; - compilers.serviceworker.watch({}, (err: Error, stats: any) => { - if (err) { - // TODO notify client - } else if (stats.hasErrors()) { - // print errors. TODO notify client - stats.toJson().errors.forEach((error: Error) => { - console.error(error); // TODO make this look nice - }); - } else { - console.log(`built service worker in ${Date.now() - times.serviceworker_start}ms`); // TODO prettify + compilers.serviceworker.plugin('invalid', (filename: string) => { + times.serviceworker_start = Date.now(); + }); - const serviceworker_info = stats.toJson(); - fs.writeFileSync(path.join(dir, 'serviceworker_info.json'), JSON.stringify(serviceworker_info, null, ' ')); - } - }); - } -} \ No newline at end of file + compilers.serviceworker.watch({}, (err: Error, stats: any) => { + if (err) { + // TODO notify client + } else if (stats.hasErrors()) { + // print errors. TODO notify client + stats.toJson().errors.forEach((error: Error) => { + console.error(error); // TODO make this look nice + }); + } else { + console.log(`built service worker in ${Date.now() - times.serviceworker_start}ms`); // TODO prettify + + const serviceworker_info = stats.toJson(); + fs.writeFileSync(path.join(dir, 'serviceworker_info.json'), JSON.stringify(serviceworker_info, null, ' ')); + } + }); + } + : noop; +} + +function noop() {} \ No newline at end of file diff --git a/src/core/create_app.ts b/src/core/create_app.ts index ec17793..87347ff 100644 --- a/src/core/create_app.ts +++ b/src/core/create_app.ts @@ -41,7 +41,7 @@ function generate_client(routes: Route[], src: string, dev: boolean, dev_port?: if (dev) { const hmr_client = posixify( - path.resolve(__dirname, 'src/hmr-client.js') + path.resolve(__dirname, 'hmr-client.js') ); code += `