Skip to content

Commit d655307

Browse files
committed
fix(@angular/pwa): support using default index option when not present
The `@angular/pwa` add schematic now attempts to discover a default index option value if a configuration usage path within the build target is possible. The default value as per the `application` build system is `<project_source_root>/index.html`.
1 parent a49d78b commit d655307

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/angular/pwa/pwa/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ export default function (options: PwaOptions): Rule {
110110

111111
// Find all index.html files in build targets
112112
const indexFiles = new Set<string>();
113+
let checkForDefaultIndex = false;
113114
for (const target of buildTargets) {
114115
if (typeof target.options?.index === 'string') {
115116
indexFiles.add(target.options.index);
117+
} else if (target.options?.index === undefined) {
118+
checkForDefaultIndex = true;
116119
}
117120

118121
if (!target.configurations) {
@@ -122,13 +125,23 @@ export default function (options: PwaOptions): Rule {
122125
for (const options of Object.values(target.configurations)) {
123126
if (typeof options?.index === 'string') {
124127
indexFiles.add(options.index);
128+
} else if (options?.index === undefined) {
129+
checkForDefaultIndex = true;
125130
}
126131
}
127132
}
128133

129134
// Setup sources for the assets files to add to the project
130135
const sourcePath = project.sourceRoot ?? posix.join(project.root, 'src');
131136

137+
// Check for a default index file if a configuration path allows for a default usage
138+
if (checkForDefaultIndex) {
139+
const defaultIndexFile = posix.join(sourcePath, 'index.html');
140+
if (host.exists(defaultIndexFile)) {
141+
indexFiles.add(defaultIndexFile);
142+
}
143+
}
144+
132145
// Setup service worker schematic options
133146
const { title, ...swOptions } = options;
134147

0 commit comments

Comments
 (0)