From 3c5c45835085402694dd2890975181b7f830fc0a Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Sat, 9 Jul 2022 08:05:07 -0500 Subject: [PATCH 1/3] fix: Ensure load-manifest is only generated in prod --- packages/cli/lib/lib/webpack/create-load-manifest.js | 3 ++- packages/cli/lib/lib/webpack/push-manifest.js | 6 +++++- packages/cli/lib/lib/webpack/render-html-plugin.js | 2 +- packages/cli/lib/lib/webpack/webpack-client-config.js | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/cli/lib/lib/webpack/create-load-manifest.js b/packages/cli/lib/lib/webpack/create-load-manifest.js index a66d87e38..948ee24d8 100644 --- a/packages/cli/lib/lib/webpack/create-load-manifest.js +++ b/packages/cli/lib/lib/webpack/create-load-manifest.js @@ -1,4 +1,5 @@ -module.exports = (assets, namedChunkGroups) => { +module.exports = (assets, namedChunkGroups, isProd) => { + if (!isProd) return {}; /** * This is a mapping of generic/pre-build filenames to their postbuild output * diff --git a/packages/cli/lib/lib/webpack/push-manifest.js b/packages/cli/lib/lib/webpack/push-manifest.js index d45c9a675..b9966b814 100644 --- a/packages/cli/lib/lib/webpack/push-manifest.js +++ b/packages/cli/lib/lib/webpack/push-manifest.js @@ -2,6 +2,9 @@ const webpack = require('webpack'); const createLoadManifest = require('./create-load-manifest'); module.exports = class PushManifestPlugin { + constructor(isProd) { + this.isProd = isProd; + } apply(compiler) { compiler.hooks.emit.tap( { @@ -11,7 +14,8 @@ module.exports = class PushManifestPlugin { compilation => { const manifest = createLoadManifest( compilation.assets, - compilation.namedChunkGroups + compilation.namedChunkGroups, + this.isProd ); let output = JSON.stringify(manifest); diff --git a/packages/cli/lib/lib/webpack/render-html-plugin.js b/packages/cli/lib/lib/webpack/render-html-plugin.js index 00114ac8f..04d19d99c 100644 --- a/packages/cli/lib/lib/webpack/render-html-plugin.js +++ b/packages/cli/lib/lib/webpack/render-html-plugin.js @@ -89,7 +89,7 @@ module.exports = async function (config) { if (assets['push-manifest.json']) { return JSON.parse(assets['push-manifest.json'].source()); } - return createLoadManifest(assets, namedChunkGroups); + return createLoadManifest(assets, namedChunkGroups, config.isProd); }, config, url, diff --git a/packages/cli/lib/lib/webpack/webpack-client-config.js b/packages/cli/lib/lib/webpack/webpack-client-config.js index 0ffb77a3d..57d714976 100644 --- a/packages/cli/lib/lib/webpack/webpack-client-config.js +++ b/packages/cli/lib/lib/webpack/webpack-client-config.js @@ -146,7 +146,7 @@ async function clientConfig(env) { 'process.env.ADD_SW': env.sw, 'process.env.PRERENDER': env.prerender, }), - new PushManifestPlugin(), + new PushManifestPlugin(env.isProd), ...(await renderHTMLPlugin(env)), ...getBabelEsmPlugin(env), copyPatterns.length !== 0 && From b2aae3229913e36c80c15c32f90a2a75259adb14 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Sat, 9 Jul 2022 08:06:56 -0500 Subject: [PATCH 2/3] docs: Adding changeset --- .changeset/tiny-books-flash.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tiny-books-flash.md diff --git a/.changeset/tiny-books-flash.md b/.changeset/tiny-books-flash.md new file mode 100644 index 000000000..a405cd5c0 --- /dev/null +++ b/.changeset/tiny-books-flash.md @@ -0,0 +1,5 @@ +--- +'preact-cli': patch +--- + +Fix ensures that the load-manifest is only attempted to be built in prod. It serves no use in dev (as preloading is limited to prod) and can create a race condition when used alongside HMR. From ecdbda1309ca1339d608cc09fc01ee8d4927f8f2 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Sat, 9 Jul 2022 08:09:29 -0500 Subject: [PATCH 3/3] fix: devServer live reload with `--esm` flag --- packages/cli/lib/lib/webpack/webpack-client-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/lib/lib/webpack/webpack-client-config.js b/packages/cli/lib/lib/webpack/webpack-client-config.js index 57d714976..232ed4634 100644 --- a/packages/cli/lib/lib/webpack/webpack-client-config.js +++ b/packages/cli/lib/lib/webpack/webpack-client-config.js @@ -331,7 +331,7 @@ function isDev(env) { ].filter(Boolean), devServer: { - hot: true, + hot: env.refresh, liveReload: !env.refresh, compress: true, devMiddleware: {