rollup-plugin-comlink icon indicating copy to clipboard operation
rollup-plugin-comlink copied to clipboard

Support "singleton mode" as comlink-loader

Open eight04 opened this issue 5 years ago • 1 comments

I'm looking for a plugin that is similar to comlink-loader singleton mode and found this plugin. However this feature isn't included.

I'd like to file a PR that adds a transform hook converting

import {foo} from "./my-module.worker.js";

to

import "./my-module.worker.js";
import {foo} from "comlink:./my-module.worker.js";

Therefore we can look into my-module.worker.js and extract exported names before generating the loader module.

Potential issues:

  1. Circular dependencies. Since we transform all imports of my-module.worker.js something like entry > worker > a > worker won't work.
  2. Rollup may think that entry depends on my-module.worker.js and emits a shared chunk if the module (and sub dependencies?) has side effects.

Another method is to use something like:

import _temp from "comlink:./my-module.worker.js";
const foo = _temp.foo;

But you are still not able to import names from comlink:.

eight04 avatar Dec 01 '20 09:12 eight04

@surma I think this is a great feature that I am very much in need of. Would you mind sharing your thoughts?

hendrikgaffo avatar May 28 '21 14:05 hendrikgaffo