Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with webpack 5 #698

Merged
merged 20 commits into from
Feb 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: compatibility with webpack v5
  • Loading branch information
alexander-akait committed Feb 9, 2021
commit b29c7471d9a51ae421210de0c4425e8e56a33715
18 changes: 11 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable class-methods-use-this */

import webpack from 'webpack';

import { validate } from 'schema-utils';

import CssModuleFactory from './CssModuleFactory';
Expand Down Expand Up @@ -482,6 +481,11 @@ class MiniCssExtractPlugin {
}
);
} else {
// TODO remove after drop webpack v4
const { RuntimeGlobals, runtime } = compiler.webpack
? compiler.webpack
: // eslint-disable-next-line global-require
require('webpack');
const enabledChunks = new WeakSet();
const handler = (chunk, set) => {
if (enabledChunks.has(chunk)) {
Expand All @@ -494,17 +498,17 @@ class MiniCssExtractPlugin {
typeof this.options.chunkFilename === 'string' &&
/\[(full)?hash(:\d+)?\]/.test(this.options.chunkFilename)
) {
set.add(webpack.RuntimeGlobals.getFullHash);
set.add(RuntimeGlobals.getFullHash);
}

set.add(webpack.RuntimeGlobals.publicPath);
set.add(RuntimeGlobals.publicPath);

compilation.addRuntimeModule(
chunk,
new webpack.runtime.GetChunkFilenameRuntimeModule(
new runtime.GetChunkFilenameRuntimeModule(
MODULE_TYPE,
'mini-css',
`${webpack.RuntimeGlobals.require}.miniCssF`,
`${RuntimeGlobals.require}.miniCssF`,
(referencedChunk) => {
if (!referencedChunk.contentHash[MODULE_TYPE]) {
return false;
Expand All @@ -528,10 +532,10 @@ class MiniCssExtractPlugin {
};

compilation.hooks.runtimeRequirementInTree
.for(webpack.RuntimeGlobals.ensureChunkHandlers)
.for(RuntimeGlobals.ensureChunkHandlers)
.tap(pluginName, handler);
compilation.hooks.runtimeRequirementInTree
.for(webpack.RuntimeGlobals.hmrDownloadUpdateHandlers)
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
.tap(pluginName, handler);
}
});
Expand Down