vite-plugin-prebundle-workers
v1.0.0
Published
Bundle classic Vite web workers during development.
Maintainers
Readme
Vite will bundle classic web workers at build time but not during development. This can cause some development-only bugs (ex: vitejs/vite#8470) since imports won't be supported during development but will be in production. This is a simple Vite plugin that will force your web workers to be bundled during development too.
🚀 Usage
Install
npm install vite-plugin-prebundle-workersAdd to vite config
// vite.config.js
import { defineConfig } from "vite";
import prebundleWorkers from "vite-plugin-prebundle-workers";
export default defineConfig({
plugins: [
prebundleWorkers({
include: "src/myGreatWorker.ts"
})
],
});Options are:
includeandexclude: Passed tocreateFilter(docs). One of them must be truthy or an error is thrown.configureEsBuild: A function that's given theidof the file (usually a file path) and the configuration that would be passed toesbuild.buildby default. Should return the configuration to pass toesbuild.build.
Use your Web Worker normally
const worker = new Worker(new URL("./myGreatWorker.ts", import.meta.url));A fork of...
Forked off from simple-worker-vite. This fork ended up being pretty much entirely different though so I created a new plugin instead of trying to submit patches upstream.
