Skip to content

Commit

Permalink
fix: disable load manifest in dev (#1711)
Browse files Browse the repository at this point in the history
* fix: Ensure load-manifest is only generated in prod

* docs: Adding changeset

* fix: devServer live reload with `--esm` flag
  • Loading branch information
rschristian committed Jul 28, 2022
1 parent 3f389c2 commit 5eb5d00
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .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.
3 changes: 2 additions & 1 deletion 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
*
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/lib/lib/webpack/push-manifest.js
Expand Up @@ -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(
{
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/lib/webpack/render-html-plugin.js
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/lib/webpack/webpack-client-config.js
Expand Up @@ -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 &&
Expand Down Expand Up @@ -331,7 +331,7 @@ function isDev(env) {
].filter(Boolean),

devServer: {
hot: true,
hot: env.refresh,
liveReload: !env.refresh,
compress: true,
devMiddleware: {
Expand Down

0 comments on commit 5eb5d00

Please sign in to comment.