Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
broccoli-serviceworker
Advanced tools
A broccoli plugin automating ServiceWorker file creation for Broccoli and Ember.js
ServiceWorker generator for Broccoli and Ember.js. Derived from broccoli-manifest.
For more details on ServiceWorker check out the following:
ember install broccoli-serviceworker
###Configuration By default the service worker will be generated for production builds and the service worker registration logic will be added to your index.html automatically. If you wish to add your own logic to the generated service worker, you can place that code in .js files in app/serviceworkers. Your code will have full access to Service Worker Toolbox as well as any included tools that you specify with the swIncludeFiles option. Additionally, you can further customize broccoli-serviceworker by setting configurations in your environment.js file:
//app/config/environment.js
ENV.serviceWorker = {
enabled: true,
debug: true,
precacheURLs: ['/mystaticresouce'],
excludePaths: ['test.*', 'robots.txt',],
fallback: [
'/online.html /offline.html'
],
networkFirstURLs: [
'/api/todos'
],
includeRegistration: true,
serviceWorkerFile: "service-worker.js",
skipWaiting: true,
swIncludeFiles: [
'bower_components/pouchdb/dist/pouchdb.js'
]
};
The following options are available:
{
excludePaths: ['index.html', new RegExp(/.\.map$/)],
}
{
route: '/api/todos',
method: 'any',
options: {
origin: 'https://api.example.com'
}
}
npm install --save broccoli-serviceworker
Use broccoli-serviceworker
as your last filter in the Brocfile.js
like this
var writeServiceWorker = require('broccoli-serviceworker');
...
var completeTree = mergeTrees([appJs, appCss, publicFiles]);
module.exports = mergeTrees([completeTree, writeServiceWorker((completeTree)]);
Upgrade your index.html
(see below) and you are done.
You can the options specified above as the second argument to writeServiceWorker
:
writeServiceWorker(completeTree, {
serviceWorkerFile: "service-worker.js",
excludePaths: ['test.*', 'online.html',],
precacheURLs: ['/api/offlineStates'],
fallback: [
'/api/states /api/offlineStates'
],
networkFirstURLs: [
'/api/todos'
],
skipWaiting: true
});
One additional option is available for usage with Broccoli.js:
In order to use the generated serviceworker, you will need to register the serviceworker. This is done automatically if using as an Ember.js addon. If you're not using Ember.js, you can use the following code:
<!DOCTYPE html>
<html>
...
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./service-worker.js', {scope: './'})
.catch(function(error) {
alert('Error registering service worker:'+error);
});
} else {
alert('service worker not supported');
}
</script>
</html>
FAQs
A broccoli plugin automating ServiceWorker file creation for Broccoli and Ember.js
The npm package broccoli-serviceworker receives a total of 2 weekly downloads. As such, broccoli-serviceworker popularity was classified as not popular.
We found that broccoli-serviceworker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.