rollup-plugin-replace-worker-import-meta-url v1.0.1
rollup-plugin-replace-worker-import-meta-url deprecated
⚠️ This package is deprecated as it didn't actually solve the problem it was trying to solve. There should be no reason to use this plugin.
Rollup plugin to update Worker constructors using new URL('file.js', import.meta.url)
to solve a Vite build issue.
For example, this plugin will transform the following code:
const worker = new Worker(new URL("./my-worker.js", import.meta.url));
worker.postMessage({ foo: "bar" });
Into:
const worker = new Worker(import.meta.resolve("./my-worker.js"));
worker.postMessage({ foo: "bar" });
Why?
This plugin was trying to solve a niche problem with Vite. Vite seems to have some issues with using a worker inside a worker. Unfortunately the plugin didn't actually solve the problem. I'm leaving this here for posterity but I don't recommend using it.
Installation
npm install --save-dev rollup-plugin-replace-worker-import-meta-url
Usage
// rollup.config.js
import replaceWorkerImportMetaUrl from "rollup-plugin-replace-worker-import-meta-url";
export default {
input: "src/index.js",
output: {
file: "dist/index.js",
format: "esm",
},
plugins: [replaceWorkerImportMetaUrl()],
};
Options
include
(optional)
Type: Array[RegExp | String]
When include is configured only matching files will be transformed by the plugin.
exclude
(optional)
Type: Array[RegExp | String]
When exclude is configured any matching files will not be transformed by the plugin.