Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.

Commit cafb10c

Browse files
committed
feat(worker): support (static key).ignore in ngsw-manifest.json during generation
1 parent bcaf125 commit cafb10c

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

service-worker/worker/gulpfile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ gulp.task('task:webpack_test:pack', done => {
130130
},
131131
plugins: [
132132
new CopyWebpackPlugin([
133+
{from: 'other.js'},
134+
{from: 'ignored.js'},
133135
{from: 'ngsw-manifest.json'},
134136
]),
135137
new AngularServiceWorkerPlugin({baseHref: '/test'}),

service-worker/worker/src/build/gulp.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,20 @@ export function gulpAddStaticFiles(files: any, options: GulpAddStaticFileOptions
3737
let property = options.manifestKey || 'static';
3838
manifest[property] = staticConfig;
3939

40+
// Look for ignored patterns in the manifest.
41+
let ignored: RegExp[] = [];
42+
const ignoreKey = `${options.manifestKey}.ignore`;
43+
if (manifest.hasOwnProperty(ignoreKey)) {
44+
ignored.push(...(manifest[ignoreKey] as string[])
45+
.map(regex => new RegExp(regex)));
46+
delete manifest[ignoreKey];
47+
}
48+
4049
files.on('data', file => {
50+
const url = '/' + file.relative;
51+
if (ignored.some(regex => regex.test(url))) {
52+
return;
53+
}
4154
staticConfig.urls['/' + file.relative] = sha1(file.contents);
4255
});
4356
files.on('end', () => {

service-worker/worker/src/build/webpack.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export class AngularServiceWorkerPlugin {
4747
throw new Error(`Manifest already contains key: ${this.manifestKey}`);
4848
}
4949

50+
// Look for ignored patterns in the manifest.
51+
let ignored: RegExp[] = [];
52+
const ignoreKey = `${this.manifestKey}.ignore`;
53+
if (manifest.hasOwnProperty(ignoreKey)) {
54+
ignored.push(...(manifest[ignoreKey] as string[])
55+
.map(regex => new RegExp(regex)));
56+
delete manifest[ignoreKey];
57+
}
58+
5059
// Map of urls to hashes.
5160
let urls = {};
5261
manifest[this.manifestKey] = {urls, _generatedFromWebpack: true};
@@ -57,6 +66,9 @@ export class AngularServiceWorkerPlugin {
5766
.filter(key => key !== this.manifestFile)
5867
.forEach(key => {
5968
let url = `${this.baseHref}${key}`;
69+
if (ignored.some(regex => regex.test(url))) {
70+
return;
71+
}
6072
urls[url] = sha1(compilation.assets[key].source());
6173
});
6274

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('i should not make it');
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"other": true
2+
"other": true,
3+
"static.ignore": [
4+
"^\/test\/ig.*$"
5+
]
36
}

0 commit comments

Comments
 (0)