developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.04k stars 362 forks source link

The compressed variables in the output commonjs format file will be rewritten $ #920

Closed JokerFe closed 2 years ago

JokerFe commented 2 years ago

After the packed file compresses the variable name, it will use $, causing the $of jQuery to be overwritten image

developit commented 2 years ago

This is working as intended. CommonJS modules are executed within a wrapper function ((function(module,exports,require){ /* code */ })(), so those variables are scoped and should not be overwriting anything.

It sounds like you're running the CommonJS bundle without actually using a CommonJS loader, which won't work. I would recommend using the umd, iife or es module types instead.