Skip to content

Commit 5eb5d00

Browse files
authored
fix: disable load manifest in dev (#1711)
* fix: Ensure load-manifest is only generated in prod * docs: Adding changeset * fix: devServer live reload with `--esm` flag
1 parent 3f389c2 commit 5eb5d00

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

.changeset/tiny-books-flash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-cli': patch
3+
---
4+
5+
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.

packages/cli/lib/lib/webpack/create-load-manifest.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
module.exports = (assets, namedChunkGroups) => {
1+
module.exports = (assets, namedChunkGroups, isProd) => {
2+
if (!isProd) return {};
23
/**
34
* This is a mapping of generic/pre-build filenames to their postbuild output
45
*

packages/cli/lib/lib/webpack/push-manifest.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const webpack = require('webpack');
22
const createLoadManifest = require('./create-load-manifest');
33

44
module.exports = class PushManifestPlugin {
5+
constructor(isProd) {
6+
this.isProd = isProd;
7+
}
58
apply(compiler) {
69
compiler.hooks.emit.tap(
710
{
@@ -11,7 +14,8 @@ module.exports = class PushManifestPlugin {
1114
compilation => {
1215
const manifest = createLoadManifest(
1316
compilation.assets,
14-
compilation.namedChunkGroups
17+
compilation.namedChunkGroups,
18+
this.isProd
1519
);
1620

1721
let output = JSON.stringify(manifest);

packages/cli/lib/lib/webpack/render-html-plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ module.exports = async function (config) {
8989
if (assets['push-manifest.json']) {
9090
return JSON.parse(assets['push-manifest.json'].source());
9191
}
92-
return createLoadManifest(assets, namedChunkGroups);
92+
return createLoadManifest(assets, namedChunkGroups, config.isProd);
9393
},
9494
config,
9595
url,

packages/cli/lib/lib/webpack/webpack-client-config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async function clientConfig(env) {
146146
'process.env.ADD_SW': env.sw,
147147
'process.env.PRERENDER': env.prerender,
148148
}),
149-
new PushManifestPlugin(),
149+
new PushManifestPlugin(env.isProd),
150150
...(await renderHTMLPlugin(env)),
151151
...getBabelEsmPlugin(env),
152152
copyPatterns.length !== 0 &&
@@ -331,7 +331,7 @@ function isDev(env) {
331331
].filter(Boolean),
332332

333333
devServer: {
334-
hot: true,
334+
hot: env.refresh,
335335
liveReload: !env.refresh,
336336
compress: true,
337337
devMiddleware: {

0 commit comments

Comments
 (0)