[Feature]: provide option to stop injecting __webpack_exports__ and __WEBPACK_EXTERNAL_MODULE_ variable prefix
What problem does this feature solve?
Both variable prefixes __webpack_exports__ and __WEBPACK_EXTERNAL_MODULE_, as long as the Great Wall or Yangtze, reduce the readability and debuggability of output .js files.
import * as __WEBPACK_EXTERNAL_MODULE_micromark_extension_cjk_friendly_1c72e10b__ from "micromark-extension-cjk-friendly";
function remarkCjkFriendly() {
const data = this.data();
const micromarkExtensions = data.micromarkExtensions || (data.micromarkExtensions = []);
micromarkExtensions.push((0, __WEBPACK_EXTERNAL_MODULE_micromark_extension_cjk_friendly_1c72e10b__.cjkFriendlyExtension)());
}
export { remarkCjkFriendly as default };
If you want to keep the output readable, this specification is a barrier.
What does the proposed API look like?
A boolean property of a object passed to an argument of defineConfig in rslib.config.ts.
import { defineConfig } from "@rslib/core";
export default defineConfig({
lib: [
{
format: "esm",
syntax: "es2024",
dts: true,
bundle: false,
// ***HERE***
},
],
});
By this option, the output will be much more readable:
import { cjkFriendlyExtension } from "micromark-extension-cjk-friendly";
function remarkCjkFriendly() {
const data = this.data();
const micromarkExtensions = data.micromarkExtensions || (data.micromarkExtensions = []);
micromarkExtensions.push((0, cjkFriendlyExtension)());
}
export { remarkCjkFriendly as default };
-
__WEBPACK_EXTERNAL_MODULE_is a known issue that will break the readability of the output files, also see _WEBPACK_EXTERNAL_MODULE. - Could you specify the issue with
__webpack_exports__? I think it's about the CJS format?
@fi3ework
Could you specify the issue with webpack_exports? I think it's about the CJS format?
It appears when you re-export other ESMs with bundle: false.
https://github.com/tats-u/rslib-var-prefix
export { checkCjk } from "./body.js";
↓
import * as __WEBPACK_EXTERNAL_MODULE__body_js_551ed84c__ from "./body.js";
var __webpack_exports__check = __WEBPACK_EXTERNAL_MODULE__body_js_551ed84c__.check;
export { __webpack_exports__check as check };
I should have reported this as a bug.
Well, technically it's not a bug as even in this format it keeps the same semantic as the expected one, and tree shaking also performs normally.
But it's terrible for readability.
I see. For Rslib, I think this should be rather the default behavior. Due to this, I migrated from Rslib to tsup in https://github.com/tats-u/markdown-cjk-friendly for a while.
The output style is defined by webpack / Rspack internal mechanism, but we should tweak it for Rslib.
Is it exposed to Rspack users (including Rslib)? (Which court is the ball in now, Rspack or Rslib?)
Will be changed in Rspack side.