Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
rollup-plugin-workbox
Advanced tools
Rollup plugin that builds a service worker with workbox as part of your rollup build
Rollup plugin that builds a service worker with workbox as part of your rollup build
This package provides two rollup plugins: one that generates a complete service worker for you and one that generates a list of assets to precache that is injected into a service worker file.
The plugins are implemented as two function in the rollup-plugin-workbox module, named generateSW
and injectManifest
.
generateSW
Import the generateSW
plugin from rollup-plugin-workbox
, and add it to your plugins
array in your rollup.config.js
. The plugin takes a workbox config object, and an optional render function as the second argument.
You can find a detailed list of supported properties for the workbox config object here.
const { generateSW } = require('rollup-plugin-workbox');
module.exports = {
input: 'main.js',
output: {
file: 'dist/bundle.js',
format: 'esm',
},
plugins: [
generateSW({
swDest: '/dist/sw.js',
globDirectory: 'demo/dist/',
}),
],
};
You can also require
your workbox-config.js
file and pass it to the plugin.
const { generateSW } = require('rollup-plugin-workbox');
const workboxConfig = require('./workbox-config.js');
module.exports = {
// ...
plugins: [generateSW(workboxConfig)],
};
You can also customize the console output after workbox has generated your service worker by passing an optional render function as the second argument to the plugin:
const { generateSW } = require('rollup-plugin-workbox');
const workboxConfig = require('./workbox-config.js');
module.exports = {
// ...
plugins: [
generateSW(workboxConfig, {
render: ({ swDest, count, size }) => {
console.log('📦', swDest, '#️⃣', count, '🐘', size);
},
}),
],
};
injectManifest
Import the injectManifest
plugin from rollup-plugin-workbox
, and add it to your plugins
array in your rollup.config.js
. The plugin takes a workbox config object, and an optional render function as the second argument.
You can find a detailed list of supported properties for the workbox config object here.
const { injectManifest } = require('rollup-plugin-workbox');
module.exports = {
input: 'main.js',
output: {
file: 'dist/bundle.js',
format: 'esm',
},
plugins: [
injectManifest({
swSrc: 'sw.js',
swDest: '/dist/sw.js',
globDirectory: 'demo/dist/',
}),
],
};
You can also require
your workbox-config.js
file and pass it to the plugin.
const { injectManifest } = require('rollup-plugin-workbox');
const workboxConfig = require('./workbox-config.js');
module.exports = {
// ...
plugins: [injectManifest(workboxConfig)],
};
You can also customize the console output after workbox has created your service worker by passing an optional render function as the second argument to the plugin:
const { injectManifest } = require('rollup-plugin-workbox');
const workboxConfig = require('./workbox-config.js');
module.exports = {
// ...
plugins: [
injectManifest(workboxConfig, {
render: ({ swDest, count, size }) => {
console.log('📦', swDest, '#️⃣', count, '🐘', size);
},
}),
],
};
When using injectManifest
, your service worker will also automatically get bundled via esbuild
. During bundling, any mentions of Workbox's internal usage of process.env
variables will also be replaced, so you'll end up with a service worker that will have browser-compatible syntax only.
You can override the esbuild
options used like so:
const { injectManifest } = require('rollup-plugin-workbox');
const workboxConfig = require('./workbox-config.js');
module.exports = {
// ...
plugins: [
injectManifest(workboxConfig, {
esbuild: {
minify: false,
},
}),
],
};
FAQs
Rollup plugin that builds a service worker with workbox as part of your rollup build
We found that rollup-plugin-workbox demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.