Skip to content

Commit

Permalink
add support for webpack4 (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
andriijas authored and goldhand committed Feb 22, 2018
1 parent 3791489 commit 25beca4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ module.exports = {
}
```

### `importSripts` usage example
### `importScripts` usage example

Accepts an array of `<String|Object>`'s. `String` entries are legacy supported. Use `filename` instead.

Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 25beca4

Please sign in to comment.