https://github.com/ianpurvis/rollup-plugin-fork
A rollup plugin that spawns rollup, emitting the output back into the main bundle.
https://github.com/ianpurvis/rollup-plugin-fork
fork plugins rollup rollup-plugins worker
Last synced: 3 months ago
JSON representation
A rollup plugin that spawns rollup, emitting the output back into the main bundle.
- Host: GitHub
- URL: https://github.com/ianpurvis/rollup-plugin-fork
- Owner: ianpurvis
- License: mit
- Created: 2020-11-26T19:27:42.000Z (over 5 years ago)
- Default Branch: trunk
- Last Pushed: 2025-04-10T13:34:46.000Z (about 1 year ago)
- Last Synced: 2025-10-06T11:31:55.519Z (8 months ago)
- Topics: fork, plugins, rollup, rollup-plugins, worker
- Language: JavaScript
- Homepage:
- Size: 986 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/ianpurvis/rollup-plugin-fork/actions/workflows/continuous.yml)
[](https://codecov.io/gh/ianpurvis/rollup-plugin-fork)
# rollup-plugin-fork
A rollup plugin that spawns rollup, emitting the output back into the main bundle.
## Install
$ npm i -D rollup-plugin-fork
## Options
### `include` [string] | [RegExp] | [string]\[\] | [RegExp]\[\]
Regular expression or [picomatch] pattern that includes files.
Nothing is included by default.
### `exclude` [string] | [RegExp] | [string]\[\] | [RegExp]\[\]
Regular expression or [picomatch] pattern that excludes files.
Nothing is excluded by default.
### `inputOptions` [InputOptions] | (options: [InputOptions]) => [InputOptions]
Input options to be used when spawning rollup. By default, the plugin will
inherit all options from the main bundle except for `input`. You can
specify an options object to be spread into the inherited options, or a
transform function receiving the inherited options and returning their
replacement.
If a transform function is specified, it will be invoked for each module
included by the plugin and will receive options where `input` is the absolute
module path. This can be used to drive transform logic, but note that
modifying or deleting `input` will result in an error.
### `outputOptions` [OutputOptions] | (options: [OutputOptions]) => [OutputOptions]
Output options to be used when spawning rollup. By default, the plugin will
inherit all options from the main bundle except for `dir` and `file`. You
can specify an options object to be spread into the inherited options, or a
transform function receiving the inherited options and returning their
replacement.
If you specify `dir`, it will be relative to the `dir` of the main output.
[RegExp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
[String]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
[picomatch]: https://github.com/micromatch/picomatch#globbing-features
[InputOptions]: https://rollupjs.org/guide/en/#big-list-of-options
[OutputOptions]: https://rollupjs.org/guide/en/#big-list-of-options
## Web Worker Example
The following example outputs an ES bundle with an IIFE web worker asset.
`format` is overridden while `entryFileNames` is inherited to give the worker a
hashed file name.
**main.js**
import workerUrl from './worker.js'
new Worker(workerUrl).onmessage = ({ data }) => document.body.append(data)
**worker.js**
import hello from './helper.js'
postMessage(hello)
**helper.js**
export default '👋'
**rollup.config.js**
import fork from 'rollup-plugin-fork'
export default {
input: 'main.js',
output: {
entryFileNames: '[name]-[hash].js'
format: 'es'
},
plugins: [
fork({
include: /worker\.js$/,
outputOptions: {
format: 'iife'
}
})
]
}
**output:**
$ npx rollup -c
main.js → stdout...
//→ main-78fc96ad.js:
var workerUrl = new URL('worker-0f27d5dd.js', import.meta.url).href;
new Worker(workerUrl).onmessage = ({ data }) => document.body.append(data);
//→ worker-0f27d5dd.js:
(function () {
'use strict';
var hello = '👋';
postMessage(hello);
}());
## License
This package is available as open source under the terms of the
[MIT License](http://opensource.org/licenses/MIT).
[](https://purvisresearch.com)