Skip to content

Release NPM packages for different environments #11

@tomvoet

Description

@tomvoet

As of right now the NPM package @refilelabs/image is built via wasm-pack build --target web --release.
While this works fine for browser-based applications, it causes compatibility issues in other environments such as node (see #6) or even extensions (see blog article (Chinese)).

To improve compatibility, we could:

  1. Publish multiple targets under corresponding directories, allowing users to import based on their environment:
    import { ... } from "@refilelabs/image/browser";
    import { ... } from "@refilelabs/image/node";
  2. Use the exports field in package.json to define separate entry points for different environments:
    {
      "exports": {
        "browser": "./browser/index.js",
        "node": "./node/index.js",
        "default": "./browser/index.js"
      }
    }
    This way, bundlers automatically pick the correct version.
  3. Switch to a more general wasm-pack target, such as:
    • bundler: Works well with Webpack/Rollup and is more flexible.
    • no-modules: Provides maximum compatibility but requires manual setup.
    • nodejs: A separate build for Node.js.

Any feedback or ideas are very welcome. While this most likely will cause a breaking change, I think the benefits will be well worth it in the long run.
@Trojanking123, since you've researched this topic, I'd really appreciate your input!

P.S. this seems to be a highly discussed topic (see drager/wasm-pack#313). Currently, the primary solution to this seems to be building multiple times and then merging into one package.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions