Skip to content

Commit

Permalink
fix(@angular/cli): fix ever increasing lazy chunk name counter
Browse files Browse the repository at this point in the history
Currently, rebuilds with lazy modules keep increasing the lazy chunk name indefinitely (.0, .1, .2, etc) for the same lazy chunk. This PR fixes that.
  • Loading branch information
filipesilva authored and hansl committed Aug 10, 2017
1 parent 99eba98 commit d22c2bc
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const ImportDependency = require('webpack/lib/dependencies/ImportDependency');
export class NamedLazyChunksWebpackPlugin extends webpack.NamedChunksPlugin {
constructor() {
// Append a dot and number if the name already exists.
const nameMap = new Map<string, boolean>();
function getUniqueName(baseName: string) {
const nameMap = new Map<string, string>();
function getUniqueName(baseName: string, request: string) {
let name = baseName;
let num = 0;
while (nameMap.has(name)) {
while (nameMap.has(name) && nameMap.get(name) !== request) {
name = `${baseName}.${num++}`;
}
nameMap.set(name, true);
nameMap.set(name, request);
return name;
}

Expand All @@ -34,13 +34,13 @@ export class NamedLazyChunksWebpackPlugin extends webpack.NamedChunksPlugin {
|| chunk.blocks[0].dependencies[0] instanceof ImportDependency)
) {
// Create chunkname from file request, stripping ngfactory and extension.
const req = chunk.blocks[0].dependencies[0].request;
const chunkName = basename(req).replace(/(\.ngfactory)?\.(js|ts)$/, '');
const request = chunk.blocks[0].dependencies[0].request;
const chunkName = basename(request).replace(/(\.ngfactory)?\.(js|ts)$/, '');
if (!chunkName || chunkName === '') {
// Bail out if something went wrong with the name.
return null;
}
return getUniqueName(chunkName);
return getUniqueName(chunkName, request);
}

return null;
Expand Down

0 comments on commit d22c2bc

Please sign in to comment.