Skip to content

Commit be955ac

Browse files
committed
Support newer webpack versions.
1 parent 8cfbbd6 commit be955ac

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

RequireJsLoaderPlugin.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,24 @@ function generateEpilog(imports) {
2929
return `});`;
3030
}
3131

32+
function registerHook(object, oldName, newName, cb) {
33+
if (object.hooks) {
34+
object.hooks[newName].tap('RequireJsLoader', cb);
35+
} else {
36+
object.plugin(oldName, cb);
37+
}
38+
}
39+
3240
RequireJsLoaderPlugin.prototype.apply = function (compiler) {
33-
compiler.plugin('compilation', (compilation, data) => {
34-
compilation.plugin('chunk-asset', (chunk, filename) => {
41+
registerHook(compiler, 'compilation', 'compilation', (compilation, data) => {
42+
registerHook(compilation, 'chunk-asset', 'chunkAsset', (chunk, filename) => {
3543
// Avoid applying imports twice.
3644
if ('--requirejs-export:done' in chunk) {
3745
return;
3846
}
3947

40-
const needsImport = gatherRequireJsImports(chunk.modules);
48+
const modules = chunk.modulesIterable ? Array.from(chunk.modulesIterable) : modules;
49+
const needsImport = gatherRequireJsImports(modules);
4150
if (needsImport.length != 0) {
4251
let prolog = generateProlog(needsImport);
4352
let epilog = generateEpilog(needsImport);

0 commit comments

Comments
 (0)