Skip to content

Commit

Permalink
feat(webpack): support Webpack 3 ModuleConcatenationPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jods4 committed Jul 23, 2017
1 parent 1ea5f37 commit 457ee6f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/PreserveModuleNamePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ export class PreserveModuleNamePlugin {
roots = roots.map(x => path.resolve(x));
const normalizers = extensions.map(x => new RegExp(x.replace(/\./g, "\\.") + "$", "i"));

// ModuleConcatenationPlugin merges modules into new ConcatenatedModule
let modulesBeforeConcat = modules.slice();
for (let i = 0; i < modulesBeforeConcat.length; i++) {
let m = modulesBeforeConcat[i];
// We don't `import ConcatenatedModule` and then `m instanceof ConcatenatedModule`
// because it was introduced in Webpack 3.0 and we're still compatible with 2.x at the moment.
if (m.constructor.name === "ConcatenatedModule")
modulesBeforeConcat.splice(i--, 1, ...m["modules"]);
}

for (let module of getPreservedModules(modules)) {
let preserve: string | true | undefined = module[preserveModuleName];
let id = typeof preserve === "string" ? preserve : null;

// No absolute request to preserve, we try to normalize the module resource
if (!id && module.resource)
id = fixNodeModule(module, modules) ||
id = fixNodeModule(module, modulesBeforeConcat) ||
makeModuleRelative(roots, module.resource) ||
aliasRelative(alias, module.resource);

Expand Down

0 comments on commit 457ee6f

Please sign in to comment.