Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export async function normalizeOptions(
progress = true,
externalPackages,
deleteOutputPath,
namedChunks,
} = options;

// Return all the normalized options
Expand Down Expand Up @@ -284,6 +285,7 @@ export async function normalizeOptions(
indexHtmlOptions,
tailwindConfiguration,
i18nOptions,
namedChunks,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@
"description": "Extract all licenses in a separate file.",
"default": true
},
"namedChunks": {
"type": "boolean",
"description": "Use file name for lazy loaded chunks.",
"default": false
},
"subresourceIntegrity": {
"type": "boolean",
"description": "Enables the use of subresource integrity validation.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import { buildApplication } from '../../index';
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';

const MAIN_OUTPUT = 'dist/main.js';
const NAMED_LAZY_OUTPUT = 'dist/lazy-module-7QZXF7K7.js';
const UNNAMED_LAZY_OUTPUT = 'dist/chunk-OW5RYMPM.js';

describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
describe('Option: "namedChunks"', () => {
beforeEach(async () => {
// Setup a lazy loaded chunk
await harness.writeFiles({
'src/lazy-module.ts': 'export const value = 42;',
'src/main.ts': `import('./lazy-module');`,
});
});

it('generates named files in output when true', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
namedChunks: true,
});

const { result } = await harness.executeOnce();

expect(result?.success).toBe(true);

harness.expectFile(MAIN_OUTPUT).toExist();
harness.expectFile(NAMED_LAZY_OUTPUT).toExist();
harness.expectFile(UNNAMED_LAZY_OUTPUT).toNotExist();
});

it('does not generate named files in output when false', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
namedChunks: false,
});

const { result } = await harness.executeOnce();

expect(result?.success).toBe(true);

harness.expectFile(MAIN_OUTPUT).toExist();
harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist();
harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist();
});

it('does not generates named files in output when not present', async () => {
harness.useTarget('build', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();

expect(result?.success).toBe(true);

harness.expectFile(MAIN_OUTPUT).toExist();
harness.expectFile(NAMED_LAZY_OUTPUT).toNotExist();
harness.expectFile(UNNAMED_LAZY_OUTPUT).toExist();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const UNSUPPORTED_OPTIONS: Array<keyof BrowserBuilderOptions> = [
// 'commonChunk',

// * Unused by builder and will be removed in a future release
'namedChunks',
'vendorChunk',
'resourcesOutputPath',

Expand All @@ -43,7 +42,6 @@ export function logBuilderStatusWarnings(options: BrowserBuilderOptions, context
}

if (
unsupportedOption === 'namedChunks' ||
unsupportedOption === 'vendorChunk' ||
unsupportedOption === 'resourcesOutputPath' ||
unsupportedOption === 'deployUrl'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
outExtension: outExtension ? { '.js': `.${outExtension}` } : undefined,
sourcemap: sourcemapOptions.scripts && (sourcemapOptions.hidden ? 'external' : true),
splitting: true,
chunkNames: 'chunk-[hash]',
chunkNames: options.namedChunks ? '[name]-[hash]' : 'chunk-[hash]',
tsconfig,
external: externalDependencies,
write: false,
Expand Down