rollup-plugin-comlink
rollup-plugin-comlink copied to clipboard
Support "singleton mode" as comlink-loader
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:
- Circular dependencies. Since we transform all imports of
my-module.worker.jssomething likeentry > worker > a > workerwon't work. - Rollup may think that entry depends on
my-module.worker.jsand 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:.
@surma I think this is a great feature that I am very much in need of. Would you mind sharing your thoughts?