Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query parameters nohash and filename #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ var registerServiceWorker = require("serviceworker!./sw.js");
registerServiceWorker({ scope: '/' }).then(success, error);
```

### Options

You can pass the name of the serviceworker file as a parameter with `filename`

```javascript
var registerServiceWorker = require("serviceworker?filename=anotherserviceworker.js!./sw.js");
```

By default it adds a hash to the filename so every build it would create a different file. E.g. Would create a file 45fb4c9e6f1e0bd99735.serviceworker.js
You can remove that has option with the parameter `nohash`.

```javascript
var registerServiceWorker = require("serviceworker?nohash!./sw.js");
```

## Credit

This loader is based almost entirely on [worker-loader](https://github.com/webpack/worker-loader) by [@sokra](https://github.com/sokra).
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ module.exports.pitch = function(request) {
if(!this.webpack) throw new Error("Only usable with webpack");
var callback = this.async();
var query = loaderUtils.parseQuery(this.query);
var filename = query.filename || "serviceworker.js";
if(!query.nohash) filename = "[hash]." + filename;
var outputOptions = {
filename: "[hash].serviceworker.js",
chunkFilename: "[id].[hash].serviceworker.js",
filename: filename,
chunkFilename: "[id]." + filename,
namedChunkFilename: null
};
if(this.options && this.options.worker && this.options.worker.output) {
Expand Down