Skip to content

Compatibility of umd/amd output. #2787

Closed
@KyrieLii

Description

@KyrieLii

System Info

System:
OS: macOS 12.5.1
CPU: (10) arm64 Apple M1 Pro
Memory: 15.74 GB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.18.0/bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v16.18.0/bin/npm
Browsers:
Chrome: 112.0.5615.49
Safari: 15.6.1
npmPackages:
@rspack/cli: latest => 0.1.7

Details

Some packages output files like this:
https://github.com/aui/art-template/blob/3.1.0/dist/template-debug.js#L728

Another example is lodash (but i don't find souce code):
image

To reproduce this issue, I have written a simple demo.

...
const mmm = {a: 'a'};

if (typeof define === "function") {
  define(function () {
    return mmm;
  });
} else if (typeof exports !== "undefined") {
  module.exports = mmm;
} else {
  this.mmm = mmm;
}

You can see the difference of outputs between rspack and webpack .

rspack:

image

webpack:

image

These differences will lead to some errors .

Tks!

Reproduce link

https://github.com/KyrieLii/rspack-webpack-demo/tree/amd-0.1.7

Reproduce Steps

Pls see README.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions