diff --git a/README.md b/README.md index 3146da1..2deb8d4 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ module.exports = { } ``` -### `importSripts` usage example +### `importScripts` usage example Accepts an array of ``'s. `String` entries are legacy supported. Use `filename` instead. @@ -213,7 +213,7 @@ plugins: [ // import(/* webpackChunkName: "my-named-chunk" */ './my-async-script.js'); { chunkName: 'my-named-chunk' }, - // All importSripts entries resolve to a string, therefore + // All importScripts entries resolve to a string, therefore // the final output of the above input is: // [ // '/my/public/path/some-known-script-path.js', diff --git a/package.json b/package.json index d6e73e7..b29a4f8 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "test": "./test" }, "peerDependencies": { - "webpack": "^1 || ^2 || ^2.1.0-beta || ^2.2.0-beta || ^3" + "webpack": "^1 || ^2 || ^2.1.0-beta || ^2.2.0-beta || ^3 || ^4" }, "dependencies": { "del": "^2.2.2", diff --git a/src/index.js b/src/index.js index 2f7ba2f..355c3a4 100644 --- a/src/index.js +++ b/src/index.js @@ -68,7 +68,7 @@ class SWPrecacheWebpackPlugin { apply(compiler) { // sw-precache needs physical files to reference so we MUST wait until after assets are emitted before generating the service-worker. - compiler.plugin('after-emit', (compilation, callback) => { + const afterEmit = (compilation, callback = () => {}) => { this.configure(compiler, compilation); // configure the serviceworker options this.checkWarnings(compilation); @@ -77,7 +77,12 @@ class SWPrecacheWebpackPlugin { .then(serviceWorker => this.writeServiceWorker(serviceWorker, compiler)) .then(() => callback()) .catch(err => callback(err)); - }); + }; + if (compiler.hooks) { + compiler.hooks.afterEmit.tap('swPrecache', afterEmit); + } else { + compiler.plugin('after-emit', afterEmit); + } } configure(compiler, compilation) {