refactor(@angular-devkit/build-angular): remove resourcesOutputPath option from application builder.

This `resourcesOutputPath` option is removed from the application builder. Instead the CSS resources will always be emitted in a directory named `media`. This is preparation to output server and browser bundles in different directories.
This commit is contained in:
Alan Agius 2023-07-06 10:07:24 +00:00 committed by Douglas Parker
parent 3ccc96fd06
commit 3bb48c1c88
5 changed files with 15 additions and 21 deletions

View File

@ -94,13 +94,11 @@ export async function normalizeOptions(
? '[name].[hash]' ? '[name].[hash]'
: '[name]', : '[name]',
media: media:
options.outputHashing === OutputHashing.All || options.outputHashing === OutputHashing.Media 'media/' +
(options.outputHashing === OutputHashing.All || options.outputHashing === OutputHashing.Media
? '[name].[hash]' ? '[name].[hash]'
: '[name]', : '[name]'),
}; };
if (options.resourcesOutputPath) {
outputNames.media = path.join(options.resourcesOutputPath, outputNames.media);
}
let fileReplacements: Record<string, string> | undefined; let fileReplacements: Record<string, string> | undefined;
if (options.fileReplacements) { if (options.fileReplacements) {

View File

@ -220,10 +220,6 @@
"type": "string", "type": "string",
"description": "The full path for the new output directory, relative to the current workspace.\nBy default, writes output to a folder named dist/ in the current project." "description": "The full path for the new output directory, relative to the current workspace.\nBy default, writes output to a folder named dist/ in the current project."
}, },
"resourcesOutputPath": {
"type": "string",
"description": "The path where style resources will be placed, relative to outputPath."
},
"aot": { "aot": {
"type": "boolean", "type": "boolean",
"description": "Build using Ahead of Time compilation.", "description": "Build using Ahead of Time compilation.",

View File

@ -34,7 +34,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeTrue(); expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeTrue();
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeTrue(); expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeTrue();
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeTrue(); expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeTrue();
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeTrue(); expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeTrue();
}); });
it(`doesn't hash any filenames when not set`, async () => { it(`doesn't hash any filenames when not set`, async () => {
@ -52,7 +52,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse(); expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
}); });
it(`doesn't hash any filenames when set to "none"`, async () => { it(`doesn't hash any filenames when set to "none"`, async () => {
@ -71,7 +71,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse(); expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
}); });
it(`hashes CSS resources filenames only when set to "media"`, async () => { it(`hashes CSS resources filenames only when set to "media"`, async () => {
@ -90,7 +90,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse(); expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeFalse();
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeTrue(); expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeTrue();
}); });
it(`hashes bundles filenames only when set to "bundles"`, async () => { it(`hashes bundles filenames only when set to "bundles"`, async () => {
@ -109,11 +109,10 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeTrue(); expect(harness.hasFileMatch('dist', /main\.[0-9A-Z]{8}\.js$/)).toBeTrue();
expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeTrue(); expect(harness.hasFileMatch('dist', /polyfills\.[0-9A-Z]{8}\.js$/)).toBeTrue();
expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeTrue(); expect(harness.hasFileMatch('dist', /styles\.[0-9A-Z]{8}\.css$/)).toBeTrue();
expect(harness.hasFileMatch('dist', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse(); expect(harness.hasFileMatch('dist/media', /spectrum\.[0-9A-Z]{8}\.png$/)).toBeFalse();
}); });
// TODO: Re-enable once implemented in the esbuild builder it('does not hash non injected styles', async () => {
xit('does not hash non injected styles', async () => {
harness.useTarget('build', { harness.useTarget('build', {
...BASE_OPTIONS, ...BASE_OPTIONS,
outputHashing: OutputHashing.All, outputHashing: OutputHashing.All,
@ -159,8 +158,8 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
const { result } = await harness.executeOnce(); const { result } = await harness.executeOnce();
expect(result?.success).toBe(true); expect(result?.success).toBe(true);
harness.expectFile('dist/test.svg').toExist(); harness.expectFile('dist/media/test.svg').toExist();
harness.expectFile('dist/small-test.svg').toExist(); harness.expectFile('dist/media/small-test.svg').toExist();
}); });
}); });
}); });

View File

@ -56,6 +56,7 @@ export function logBuilderStatusWarnings(options: BrowserBuilderOptions, context
if ( if (
unsupportedOption === 'namedChunks' || unsupportedOption === 'namedChunks' ||
unsupportedOption === 'vendorChunk' || unsupportedOption === 'vendorChunk' ||
unsupportedOption === 'resourcesOutputPath' ||
unsupportedOption === 'deployUrl' unsupportedOption === 'deployUrl'
) { ) {
context.logger.warn( context.logger.warn(

View File

@ -27,7 +27,7 @@ export interface BundleStylesheetOptions {
optimization: boolean; optimization: boolean;
preserveSymlinks?: boolean; preserveSymlinks?: boolean;
sourcemap: boolean | 'external' | 'inline'; sourcemap: boolean | 'external' | 'inline';
outputNames?: { bundles?: string; media?: string }; outputNames: { bundles: string; media: string };
includePaths?: string[]; includePaths?: string[];
externalDependencies?: string[]; externalDependencies?: string[];
target: string[]; target: string[];
@ -57,8 +57,8 @@ export function createStylesheetBundleOptions(
return { return {
absWorkingDir: options.workspaceRoot, absWorkingDir: options.workspaceRoot,
bundle: true, bundle: true,
entryNames: options.outputNames?.bundles, entryNames: options.outputNames.bundles,
assetNames: options.outputNames?.media, assetNames: options.outputNames.media,
logLevel: 'silent', logLevel: 'silent',
minify: options.optimization, minify: options.optimization,
metafile: true, metafile: true,