surma / rollup-plugin-off-main-thread

Use Rollup with workers and ES6 modules today.
Apache License 2.0
308 stars 32 forks source link

Interoperability with WMR #40

Open aduh95 opened 3 years ago

aduh95 commented 3 years ago

It seems currently not possible to use this plugin with WMR:

yarn create wmr your-project-name
cd your-project-name
yarn add --dev @surma/rollup-plugin-off-main-thread
echo 'import OMT from "@surma/rollup-plugin-off-main-thread";' > wmr.config.mjs
echo 'export default async function (config) {' >> wmr.config.mjs
echo 'config.plugins.push(OMT());' >> wmr.config.mjs
echo '}' >> wmr.config.mjs
echo 'new Worker(new URL("./worker.js", import.meta.url), {type:"module"});' > public/pages/home/index.js
echo 'export default function Home() { return <div>Home</div>; }' >> public/pages/home/index.js
echo 'console.log("Worker working")' > public/pages/home/worker.js
yarn wmr build

This produces the following error:

`output.format` must either be "amd" or "esm", got "undefined"

I've tried to change the format in wmr.config.mjs but didn't get much luck.

I can work around this by changing this line https://github.com/surma/rollup-plugin-off-main-thread/blob/0dc070bffac2cdde9fd85ef24010415d87186e86/index.js#L204 to

if (format === "esm" || format === "es" || format === undefined) {

Is interoperability with WMR something on the roadmap?

surma commented 3 years ago

@developit wdyt?

developit commented 3 years ago

I have a demo of this somewhere, I'll dig it up. Using it in WMR requires a bit of tweaking because it needs to use Module Workers directly in development mode.