Skip to content

Commit

Permalink
(next) - fix next 10.2 compat (#345)
Browse files Browse the repository at this point in the history
* fix next 10.2 compat

* add changeset
  • Loading branch information
JoviDeCroock committed May 21, 2021
1 parent 34ff2b4 commit c9b3bdf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-items-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@prefresh/webpack': minor
---

Use newly introduced dependency injection for webpack 5
15 changes: 13 additions & 2 deletions packages/webpack/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ class ReloadPlugin {
`);
}

compiler.options.entry = injectEntry(compiler.options.entry);

let provide = {
[prefreshUtils]: require.resolve('./utils/prefresh'),
};
Expand All @@ -152,10 +150,23 @@ class ReloadPlugin {

switch (Number(webpack.version[0])) {
case 4: {
compiler.options.entry = injectEntry(compiler.options.entry);
this.webpack4(compiler);
break;
}
case 5: {
const dependency = webpack.EntryPlugin.createDependency(
'@prefresh/core',
{ name: '@prefresh/core' }
);
compiler.hooks.make.tapAsync(NAME, (compilation, callback) => {
compilation.addEntry(
compiler.context,
dependency,
undefined,
callback
);
});
this.webpack5(compiler);
break;
}
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/next-webpack5/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const config = {
},
webpack(config, { dev, isServer }) {
const splitChunks = config.optimization && config.optimization.splitChunks;
if (splitChunks) {
if (splitChunks && isServer && splitChunks.cacheGroups) {
const cacheGroups = splitChunks.cacheGroups;
const preactModules = /[\\/]node_modules[\\/](preact|preact-render-to-string|preact-context-provider)[\\/]/;

if (cacheGroups.framework) {
cacheGroups.preact = Object.assign({}, cacheGroups.framework, {
test: preactModules
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/next-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"goober": "latest",
"next": "^10.0.7",
"next": "^10.2.2",
"preact": "^10.5.7",
"preact-render-to-string": "^5.1.12",
"react": "github:preact-compat/react#1.0.0",
Expand Down

0 comments on commit c9b3bdf

Please sign in to comment.