Skip to content

Support "singleton mode" as comlink-loader #1

Description

@eight04

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:.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions