Skip to content

Commit aa6aee1

Browse files
alan-agius4vikerman
authored andcommitted
fix(@schematics/angular): universal add outputHashing to media
In case the browser builder hashes the assets we need to add this setting to the server builder as otherwise when assets it will be requested twice. One for the server which will be unhashed, and other on the client which will be hashed. Closes #15953
1 parent bc89e67 commit aa6aee1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/schematics/angular/universal/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { addPackageJsonDependency, getPackageJsonDependency } from '../utility/d
3636
import { findBootstrapModuleCall, findBootstrapModulePath } from '../utility/ng-ast-utils';
3737
import { targetBuildNotFoundError } from '../utility/project-targets';
3838
import { getWorkspace, updateWorkspace } from '../utility/workspace';
39-
import { BrowserBuilderOptions, Builders } from '../utility/workspace-models';
39+
import { BrowserBuilderOptions, Builders, OutputHashing } from '../utility/workspace-models';
4040
import { Schema as UniversalOptions } from './schema';
4141

4242
function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): Rule {
@@ -53,6 +53,20 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R
5353
buildTarget.options.outputPath = `dist/${options.clientProject}/browser`;
5454
}
5555

56+
// In case the browser builder hashes the assets
57+
// we need to add this setting to the server builder
58+
// as otherwise when assets it will be requested twice.
59+
// One for the server which will be unhashed, and other on the client which will be hashed.
60+
let outputHashing: OutputHashing | undefined;
61+
if (buildTarget && buildTarget.configurations && buildTarget.configurations.production) {
62+
switch (buildTarget.configurations.production.outputHashing as OutputHashing) {
63+
case 'all':
64+
case 'media':
65+
outputHashing = 'media';
66+
break;
67+
}
68+
}
69+
5670
const mainPath = options.main as string;
5771
clientProject.targets.add({
5872
name: 'server',
@@ -64,6 +78,7 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R
6478
},
6579
configurations: {
6680
production: {
81+
outputHashing,
6782
fileReplacements,
6883
sourceMap: false,
6984
optimization: true,

packages/schematics/angular/universal/index_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ describe('Universal Schematic', () => {
155155
const configurations = targets.server.configurations;
156156
expect(configurations.production).toBeDefined();
157157
expect(configurations.production.fileReplacements).toBeDefined();
158+
expect(configurations.production.outputHashing).toBe('media');
158159
const fileReplacements = targets.server.configurations.production.fileReplacements;
159160
expect(fileReplacements.length).toEqual(1);
160161
expect(fileReplacements[0].replace).toEqual('projects/bar/src/environments/environment.ts');

0 commit comments

Comments
 (0)