Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johanholmerin/rollup-plugin-workers
Worker and Worklets code splitting support for Rollup
https://github.com/johanholmerin/rollup-plugin-workers
Last synced: 3 months ago
JSON representation
Worker and Worklets code splitting support for Rollup
- Host: GitHub
- URL: https://github.com/johanholmerin/rollup-plugin-workers
- Owner: johanholmerin
- License: mit
- Created: 2018-10-30T09:44:12.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-10T18:44:26.000Z (over 2 years ago)
- Last Synced: 2024-10-03T08:11:38.748Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 48.8 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rollup-plugin-workers
Adds code splitting for module Workers and Worklets to Rollup.
## Notes
* Only for Rollup >= 1.11.0
* Does not include any module loader. See [example](example)
* Worklet calls must follow format `*.*Worklet.addModule(...)`
* File paths are resolved using Rollup## Installation
```sh
# Yarn
yarn add -D rollup-plugin-workers# npm
npm install -D rollup-plugin-workers
```## Usage
**rollup.config.js**
```javascript
import worker from 'rollup-plugin-workers';export default {
input: 'main.js',
output: {
dir: 'dist/system',
format: 'system'
},
plugins: [
worker()
]
};
```**main.js**
```javascript
// workers have to be of `type: 'module'`
new Worker('./dedicated-worker.js', { type: 'module' })
new SharedWorker('./shared-worker.js', { type: 'module' })
navigator.serviceWorker.register('./sw.js', { type: 'module' })// worklets are always modules
myAudioContext.audioWorklet.addModule('./audio-worklet.js')
CSS.paintWorklet.addModule('./paint-worklet.js')
CSS.layoutWorklet.addModule('./layout-worklet.js')
CSS.animationWorklet.addModule('./animation-worklet.js')
```