diff --git a/packages/@angular/cli/models/webpack-configs/production.ts b/packages/@angular/cli/models/webpack-configs/production.ts index 904cd5468ba1..1a9003e5ad96 100644 --- a/packages/@angular/cli/models/webpack-configs/production.ts +++ b/packages/@angular/cli/models/webpack-configs/production.ts @@ -58,8 +58,12 @@ export const getProdConfig = function (wco: WebpackConfigOptions) { } extraPlugins.push(new GlobCopyWebpackPlugin({ - patterns: ['ngsw-manifest.json', 'src/ngsw-manifest.json'], + patterns: [ + 'ngsw-manifest.json', + {glob: 'ngsw-manifest.json', input: path.resolve(projectRoot, appConfig.root), output: ''} + ], globOptions: { + cwd: projectRoot, optional: true, }, })); diff --git a/tests/e2e/tests/build/service-worker.ts b/tests/e2e/tests/build/service-worker.ts index 4277a7a10020..aaec76d54c85 100644 --- a/tests/e2e/tests/build/service-worker.ts +++ b/tests/e2e/tests/build/service-worker.ts @@ -1,6 +1,6 @@ import {join} from 'path'; import {getGlobalVariable} from '../../utils/env'; -import {expectFileToExist, expectFileToMatch} from '../../utils/fs'; +import {expectFileToExist, expectFileToMatch, writeFile, moveFile} from '../../utils/fs'; import {ng, npm} from '../../utils/process'; export default function() { @@ -9,6 +9,8 @@ export default function() { return Promise.resolve(); } + const rootManifest = join(process.cwd(), 'ngsw-manifest.json'); + // Can't use the `ng` helper because somewhere the environment gets // stuck to the first build done return npm('install', '@angular/service-worker') @@ -18,5 +20,11 @@ export default function() { .then(() => expectFileToExist(join(process.cwd(), 'dist/ngsw-manifest.json'))) .then(() => ng('build', '--prod', '--base-href=/foo/bar')) .then(() => expectFileToExist(join(process.cwd(), 'dist/ngsw-manifest.json'))) - .then(() => expectFileToMatch('dist/ngsw-manifest.json', /"\/foo\/bar\/index.html"/)); + .then(() => expectFileToMatch('dist/ngsw-manifest.json', /"\/foo\/bar\/index.html"/)) + .then(() => writeFile(rootManifest, '{"local": true}')) + .then(() => ng('build', '--prod')) + .then(() => expectFileToMatch('dist/ngsw-manifest.json', /\"local\"/)) + .then(() => moveFile(rootManifest, join(process.cwd(), 'src/ngsw-manifest.json'))) + .then(() => ng('build', '--prod')) + .then(() => expectFileToMatch('dist/ngsw-manifest.json', /\"local\"/)); }