Skip to content

Commit

Permalink
feat(@angular-devkit/build-webpack): include entrypoints in emitted f…
Browse files Browse the repository at this point in the history
…iles

Entrypoints might have other files associate with them such as runtime.js, it is is paramount to keep the relation between them especially when this result is needed to generate an index file
  • Loading branch information
Alan Agius authored and alexeagle committed Apr 10, 2019
1 parent 6dac818 commit 55863a5
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions packages/angular_devkit/build_webpack/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,32 @@ export interface EmittedFiles {
export function getEmittedFiles(compilation: webpack.compilation.Compilation): EmittedFiles[] {
const files: EmittedFiles[] = [];

for (const chunk of Object.values(compilation.chunks)) {
const entry: Partial<EmittedFiles> = {
name: chunk.name,
initial: chunk.isOnlyInitial(),
};

for (const file of chunk.files) {
files.push({ ...entry, file, extension: path.extname(file) } as EmittedFiles);
// entrypoints might have multiple outputs
// such as runtime.js
for (const [name, entrypoint] of compilation.entrypoints) {
const entryFiles: string[] = (entrypoint && entrypoint.getFiles()) || [];
for (const file of entryFiles) {
files.push({ name, file, extension: path.extname(file), initial: true });
}
}

for (const file of Object.keys(compilation.assets)) {
if (files.some(e => e.file === file)) {
// skip as this already exists
continue;
// adds all chunks to the list of emitted files such as lazy loaded modules
for (const chunk of Object.values(compilation.chunks)) {
for (const file of chunk.files as string[]) {
files.push({
name: chunk.name,
file,
extension: path.extname(file),
initial: chunk.isOnlyInitial(),
});
}
}

files.push({
file,
extension: path.extname(file),
initial: false,
});
// other all files
for (const file of Object.keys(compilation.assets)) {
files.push({ file, extension: path.extname(file), initial: false });
}

return files;
// dedupe
return files.filter(({ file }, index) => files.findIndex(f => f.file === file) === index);
}

0 comments on commit 55863a5

Please sign in to comment.