From 835b94175d3b3c2d7ceffd50875e94a530138a0a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 18 Feb 2018 12:49:37 -0500 Subject: [PATCH] workaround weird webpack(?) bug by not deleting old files --- src/cli/dev.ts | 10 ++++------ src/hmr-client.js | 2 ++ src/middleware/index.ts | 6 ------ src/webpack/index.ts | 6 +++--- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/cli/dev.ts b/src/cli/dev.ts index 30273d2..835911e 100644 --- a/src/cli/dev.ts +++ b/src/cli/dev.ts @@ -154,10 +154,9 @@ export default async function dev(src: string, dir: string) { deferreds.client = deferred(); - // TODO print message - fs.readdirSync(path.join(dir, 'client')).forEach(file => { - fs.unlinkSync(path.join(dir, 'client', file)); - }); + // TODO we should delete old assets. due to a webpack bug + // i don't even begin to comprehend, this is apparently + // quite difficult }); compilers.client.watch({}, (err: Error, stats: any) => { @@ -196,7 +195,7 @@ export default async function dev(src: string, dir: string) { times.serviceworker_start = Date.now(); }); - compilers.client.watch({}, (err: Error, stats: any) => { + compilers.serviceworker.watch({}, (err: Error, stats: any) => { if (err) { // TODO notify client } else if (stats.hasErrors()) { @@ -209,7 +208,6 @@ export default async function dev(src: string, dir: string) { const serviceworker_info = stats.toJson(); fs.writeFileSync(path.join(dir, 'serviceworker_info.json'), JSON.stringify(serviceworker_info, null, ' ')); - // TODO trigger reload? } }); } diff --git a/src/hmr-client.js b/src/hmr-client.js index 88938dc..fa478b9 100644 --- a/src/hmr-client.js +++ b/src/hmr-client.js @@ -1,5 +1,7 @@ let source; +console.log('!!!! hmr client'); + function check() { if (module.hot.status() === 'idle') { module.hot.check(true).then(modules => { diff --git a/src/middleware/index.ts b/src/middleware/index.ts index cd2f146..90ef0ca 100644 --- a/src/middleware/index.ts +++ b/src/middleware/index.ts @@ -12,12 +12,6 @@ import { Route, Template } from '../interfaces'; const dev = isDev(); -type Assets = { - index: string; - service_worker: string; - client: Record; -} - type RouteObject = { id: string; type: 'page' | 'route'; diff --git a/src/webpack/index.ts b/src/webpack/index.ts index c387fad..6725a50 100644 --- a/src/webpack/index.ts +++ b/src/webpack/index.ts @@ -18,8 +18,8 @@ export default { output: () => { return { path: `${dest}/client`, - filename: '[name].[hash].js', - chunkFilename: '[name].[id].[hash].js', + filename: '[hash]/[name].js', + chunkFilename: '[hash]/[name].[id].js', publicPath: '/client/' }; } @@ -36,7 +36,7 @@ export default { return { path: `${dest}`, filename: '[name].js', - chunkFilename: '[name].[id].[hash].js', + chunkFilename: '[hash]/[name].[id].js', libraryTarget: 'commonjs2' }; }