diff --git a/goldens/public-api/angular_devkit/build_angular/index.md b/goldens/public-api/angular_devkit/build_angular/index.md index f912d7001e8c..19a46f29ecdf 100644 --- a/goldens/public-api/angular_devkit/build_angular/index.md +++ b/goldens/public-api/angular_devkit/build_angular/index.md @@ -79,7 +79,7 @@ export interface AssetPatternObject { glob: string; ignore?: string[]; input: string; - output: string; + output?: string; } // @public diff --git a/packages/angular/pwa/pwa/files/root/manifest.webmanifest b/packages/angular/pwa/pwa/files/assets/manifest.webmanifest similarity index 100% rename from packages/angular/pwa/pwa/files/root/manifest.webmanifest rename to packages/angular/pwa/pwa/files/assets/manifest.webmanifest diff --git a/packages/angular/pwa/pwa/index.ts b/packages/angular/pwa/pwa/index.ts index f817c4764905..2710247a619f 100644 --- a/packages/angular/pwa/pwa/index.ts +++ b/packages/angular/pwa/pwa/index.ts @@ -104,23 +104,6 @@ export default function (options: PwaOptions): Rule { } } - // Add manifest to asset configuration - const assetEntry = posix.join( - project.sourceRoot ?? posix.join(project.root, 'src'), - 'manifest.webmanifest', - ); - for (const target of [...buildTargets, ...testTargets]) { - if (target.options) { - if (Array.isArray(target.options.assets)) { - target.options.assets.push(assetEntry); - } else { - target.options.assets = [assetEntry]; - } - } else { - target.options = { assets: [assetEntry] }; - } - } - // Find all index.html files in build targets const indexFiles = new Set(); for (const target of buildTargets) { @@ -146,11 +129,32 @@ export default function (options: PwaOptions): Rule { const { title, ...swOptions } = options; await writeWorkspace(host, workspace); + let assetsDir = posix.join(sourcePath, 'assets'); + + if (host.exists(assetsDir)) { + // Add manifest to asset configuration + const assetEntry = posix.join( + project.sourceRoot ?? posix.join(project.root, 'src'), + 'manifest.webmanifest', + ); + for (const target of [...buildTargets, ...testTargets]) { + if (target.options) { + if (Array.isArray(target.options.assets)) { + target.options.assets.push(assetEntry); + } else { + target.options.assets = [assetEntry]; + } + } else { + target.options = { assets: [assetEntry] }; + } + } + } else { + assetsDir = posix.join(project.root, 'public'); + } return chain([ externalSchematic('@schematics/angular', 'service-worker', swOptions), - mergeWith(apply(url('./files/root'), [template({ ...options }), move(sourcePath)])), - mergeWith(apply(url('./files/assets'), [move(posix.join(sourcePath, 'assets'))])), + mergeWith(apply(url('./files/assets'), [template({ ...options }), move(assetsDir)])), ...[...indexFiles].map((path) => updateIndexFile(path)), ]); }; diff --git a/packages/angular/pwa/pwa/index_spec.ts b/packages/angular/pwa/pwa/index_spec.ts index e6b0d4e576bb..e538af1ee625 100644 --- a/packages/angular/pwa/pwa/index_spec.ts +++ b/packages/angular/pwa/pwa/index_spec.ts @@ -54,7 +54,7 @@ describe('PWA Schematic', () => { it('should create icon files', async () => { const dimensions = [72, 96, 128, 144, 152, 192, 384, 512]; - const iconPath = '/projects/bar/src/assets/icons/icon-'; + const iconPath = '/projects/bar/public/icons/icon-'; const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); dimensions.forEach((d) => { @@ -74,13 +74,13 @@ describe('PWA Schematic', () => { it('should create a manifest file', async () => { const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); - expect(tree.exists('/projects/bar/src/manifest.webmanifest')).toBeTrue(); + expect(tree.exists('/projects/bar/public/manifest.webmanifest')).toBeTrue(); }); it('should set the name & short_name in the manifest file', async () => { const tree = await schematicRunner.runSchematic('ng-add', defaultOptions, appTree); - const manifestText = tree.readContent('/projects/bar/src/manifest.webmanifest'); + const manifestText = tree.readContent('/projects/bar/public/manifest.webmanifest'); const manifest = JSON.parse(manifestText); expect(manifest.name).toEqual(defaultOptions.title); @@ -91,7 +91,7 @@ describe('PWA Schematic', () => { const options = { ...defaultOptions, title: undefined }; const tree = await schematicRunner.runSchematic('ng-add', options, appTree); - const manifestText = tree.readContent('/projects/bar/src/manifest.webmanifest'); + const manifestText = tree.readContent('/projects/bar/public/manifest.webmanifest'); const manifest = JSON.parse(manifestText); expect(manifest.name).toEqual(defaultOptions.project); @@ -125,17 +125,6 @@ describe('PWA Schematic', () => { expect(content).toMatch(/