Thanks to visit codestin.com
Credit goes to github.com

Skip to content

idiotWu/sw-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sw-loader

npm Travis License

Yet another Service Workers loader for webpack.

Install

npm install --save-dev sw-loader

Usage

This loader emits a standalone service worker file and exports the entry point.

import scriptURL from 'sw-loader!./sw.js';
// => 'scriptURL = {output.publicPath}/sw.js'
// => file location: {output.path}/sw.js

navigator.serviceWorker.register(scriptURL).then(...);

Options

name

Specify the name of output file:

import scriptURL from 'sw-loader?name=my-worker.js!./sw.js';
// => 'scriptURL = {output.publicPath}/my-worker.js'
// => file location: {output.path}/my-worker.js

Notice: this loader DOES NOT support filename interpolation, for the reason that a service worker is considered as a persistent resource.

outputPath

By default the output path follows output.path option in webpack configurations, you can change it to anywhere you like.

The outputPath will be resolved to project root.

import scriptURL from 'sw-loader?outputPath=build/workers/!./sw.js';
// => 'scriptURL = {output.publicPath}/sw.js'
// => file location: build/workers/sw.js

The outputPath modifies only the output destination, if you want to change the access URL address of service worker script, use the publicPath option below.

publicPath

By default this loader uses output.publicPath to concatenate the public URL address of service worker script, you can modify it by:

import scriptURL from 'sw-loader?publicPath=/!./sw.js';
// => 'scriptURL = /sw.js'
// => file location: {output.path}/sw.js

License

MIT

About

Yet another service worker loader

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published