Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Commit 9e6da2e

Browse files
working on webpack 5
1 parent 58b538b commit 9e6da2e

File tree

3 files changed

+202
-692
lines changed

3 files changed

+202
-692
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"puppeteer": "2.1.1",
108108
"serve": "11.3.0",
109109
"standard-version": "7.1.0",
110-
"webpack": "4.41.6",
110+
"webpack": "^5.0.0-beta.13",
111111
"webpack-cli": "3.3.11",
112112
"webpack-dev-server": "3.10.3"
113113
}

src/loader.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,31 @@ export function pitch(request) {
9191
childCompiler
9292
);
9393
new LimitChunkCountPlugin({ maxChunks: 1 }).apply(childCompiler);
94-
95-
childCompiler.hooks.thisCompilation.tap(
96-
`${pluginName} loader`,
97-
(compilation) => {
98-
compilation.hooks.normalModuleLoader.tap(
99-
`${pluginName} loader`,
100-
(loaderContext, module) => {
101-
// eslint-disable-next-line no-param-reassign
102-
loaderContext.emitFile = this.emitFile;
103-
104-
if (module.request === request) {
105-
// eslint-disable-next-line no-param-reassign
106-
module.loaders = loaders.map((loader) => {
107-
return {
108-
loader: loader.path,
109-
options: loader.options,
110-
ident: loader.ident,
111-
};
112-
});
113-
}
114-
}
115-
);
94+
childCompiler.hooks.thisCompilation.tap(`${pluginName} loader`, (compilation) => {
95+
let { normalModuleLoader } = compilation.hooks; // Webpack 4
96+
if (!normalModuleLoader) {
97+
// Webpack 5+
98+
// eslint-disable-next-line global-require
99+
const NormalModule = require('webpack/lib/NormalModule');
100+
normalModuleLoader = NormalModule.getCompilationHooks(compilation).loader;
116101
}
117-
);
102+
103+
normalModuleLoader.tap(`${pluginName} loader`, (loaderContext, module) => {
104+
// eslint-disable-next-line no-param-reassign
105+
loaderContext.emitFile = this.emitFile;
106+
107+
if (module.request === request) {
108+
// eslint-disable-next-line no-param-reassign
109+
module.loaders = loaders.map((loader) => {
110+
return {
111+
loader: loader.path,
112+
options: loader.options,
113+
ident: loader.ident,
114+
};
115+
});
116+
}
117+
});
118+
});
118119

119120
let source;
120121

0 commit comments

Comments
 (0)