Skip to content

Commit 2dd0794

Browse files
filipesilvasylvaindumont
authored andcommitted
fix(@angular-devkit/build-angular): fix service worker assets paths
Fix angular/angular-cli#10297
1 parent e475f04 commit 2dd0794

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

packages/angular_devkit/build_angular/src/server/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
import { BuildWebpackServerSchema } from './schema';
3838
const webpackMerge = require('webpack-merge');
3939

40+
import { addFileReplacements } from '../utils';
4041

4142
export class ServerBuilder implements Builder<BuildWebpackServerSchema> {
4243

@@ -46,12 +47,14 @@ export class ServerBuilder implements Builder<BuildWebpackServerSchema> {
4647
const options = builderConfig.options;
4748
const root = this.context.workspace.root;
4849
const projectRoot = resolve(root, builderConfig.root);
50+
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host<Stats>);
4951

5052
// TODO: verify using of(null) to kickstart things is a pattern.
5153
return of(null).pipe(
5254
concatMap(() => options.deleteOutputPath
5355
? this._deleteOutputDir(root, normalize(options.outputPath))
5456
: of(null)),
57+
concatMap(() => addFileReplacements(root, host, options.fileReplacements)),
5558
concatMap(() => new Observable(obs => {
5659
// Ensure Build Optimizer is only used with AOT.
5760
let webpackConfig;

packages/angular_devkit/build_angular/src/server/schema.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export interface BuildWebpackServerSchema {
7070
*/
7171
lazyModules?: string[];
7272
/**
73-
* Defines the build environment.
73+
* Replace files with other files in the build.
7474
*/
75-
environment?: string;
75+
fileReplacements: FileReplacements[];
7676
/**
7777
* Define the output filename cache-busting hashing mode.
7878
*/

packages/angular_devkit/build_angular/src/server/schema.json

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@
3232
"description": "Defines the optimization level of the build.",
3333
"default": false
3434
},
35-
"environment": {
36-
"type": "string",
37-
"description": "Defines the build environment."
35+
"fileReplacements": {
36+
"description": "Replace files with other files in the build.",
37+
"type": "array",
38+
"items": {
39+
"$ref": "#/definitions/fileReplacement"
40+
},
41+
"default": []
3842
},
3943
"outputPath": {
4044
"type": "string",
@@ -155,5 +159,37 @@
155159
"outputPath",
156160
"main",
157161
"tsConfig"
158-
]
159-
}
162+
],
163+
"definitions": {
164+
"fileReplacement": {
165+
"oneOf": [
166+
{
167+
"type": "object",
168+
"properties": {
169+
"src": {
170+
"type": "string"
171+
},
172+
"replaceWith": {
173+
"type": "string"
174+
}
175+
},
176+
"additionalProperties": false,
177+
"required": ["src", "replaceWith"]
178+
},
179+
{
180+
"type": "object",
181+
"properties": {
182+
"replace": {
183+
"type": "string"
184+
},
185+
"with": {
186+
"type": "string"
187+
}
188+
},
189+
"additionalProperties": false,
190+
"required": ["replace", "with"]
191+
}
192+
]
193+
}
194+
}
195+
}

0 commit comments

Comments
 (0)