diff --git a/packages/workbox-webpack-plugin/src/generate-sw.ts b/packages/workbox-webpack-plugin/src/generate-sw.ts index 0f125c82f..87c8cd181 100644 --- a/packages/workbox-webpack-plugin/src/generate-sw.ts +++ b/packages/workbox-webpack-plugin/src/generate-sw.ts @@ -71,6 +71,7 @@ export interface GenerateSWConfig extends WebpackGenerateSWOptions { class GenerateSW { protected config: GenerateSWConfig; private alreadyCalled: boolean; + private alreadyWarned: boolean; /** * Creates an instance of GenerateSW. @@ -78,6 +79,7 @@ class GenerateSW { constructor(config: GenerateSWConfig = {}) { this.config = config; this.alreadyCalled = false; + this.alreadyWarned = false; } /** @@ -147,22 +149,25 @@ class GenerateSW { async addAssets(compilation: webpack.Compilation): Promise { // See https://github.com/GoogleChrome/workbox/issues/1790 if (this.alreadyCalled) { - const warningMessage = - `${this.constructor.name} has been called ` + - `multiple times, perhaps due to running webpack in --watch mode. The ` + - `precache manifest generated after the first call may be inaccurate! ` + - `Please see https://github.com/GoogleChrome/workbox/issues/1790 for ` + - `more information.`; - - if ( - !compilation.warnings.some( - (warning) => - warning instanceof Error && warning.message === warningMessage, - ) - ) { - compilation.warnings.push( - Error(warningMessage) as webpack.WebpackError, - ); + if(!this.alreadyWarned) { + const warningMessage = + `${this.constructor.name} has been called ` + + `multiple times, perhaps due to running webpack in --watch mode. The ` + + `precache manifest generated after the first call may be inaccurate! ` + + `Please see https://github.com/GoogleChrome/workbox/issues/1790 for ` + + `more information.`; + + if ( + !compilation.warnings.some( + (warning) => + warning instanceof Error && warning.message === warningMessage, + ) + ) { + compilation.warnings.push( + Error(warningMessage) as webpack.WebpackError, + ); + this.alreadyWarned = true; + } } } else { this.alreadyCalled = true; diff --git a/packages/workbox-webpack-plugin/src/inject-manifest.ts b/packages/workbox-webpack-plugin/src/inject-manifest.ts index bba10344c..94d5890de 100644 --- a/packages/workbox-webpack-plugin/src/inject-manifest.ts +++ b/packages/workbox-webpack-plugin/src/inject-manifest.ts @@ -56,6 +56,7 @@ const {RawSource} = webpack.sources || require('webpack-sources'); class InjectManifest { protected config: WebpackInjectManifestOptions; private alreadyCalled: boolean; + private alreadyWarned: boolean; /** * Creates an instance of InjectManifest. @@ -63,6 +64,7 @@ class InjectManifest { constructor(config: WebpackInjectManifestOptions) { this.config = config; this.alreadyCalled = false; + this.alreadyWarned = false; } /** @@ -260,23 +262,26 @@ class InjectManifest { async addAssets(compilation: webpack.Compilation): Promise { // See https://github.com/GoogleChrome/workbox/issues/1790 if (this.alreadyCalled) { - const warningMessage = + if(!this.alreadyWarned) { + const warningMessage = `${this.constructor.name} has been called ` + `multiple times, perhaps due to running webpack in --watch mode. The ` + `precache manifest generated after the first call may be inaccurate! ` + `Please see https://github.com/GoogleChrome/workbox/issues/1790 for ` + `more information.`; - if ( - !compilation.warnings.some( - (warning) => - warning instanceof Error && warning.message === warningMessage, - ) - ) { - compilation.warnings.push( - new Error(warningMessage) as webpack.WebpackError, - ); - } + if ( + !compilation.warnings.some( + (warning) => + warning instanceof Error && warning.message === warningMessage, + ) + ) { + compilation.warnings.push( + new Error(warningMessage) as webpack.WebpackError, + ); + this.alreadyWarned = true; + } + } } else { this.alreadyCalled = true; } @@ -368,4 +373,4 @@ class InjectManifest { } } -export {InjectManifest}; +export { InjectManifest };