|
Rsbuild version: v2.1.13. Iʼm trying to set up Rsbuild for the first time, and I do not have Rslib (maybe I should use it, but I havenʼt installed it yet and Iʼm not sure I should). The target is neither Node nor web, but a java program which embeds the Rhino engine, which only supports CJS and not ESM. First, since CJS/ESM options seem to partially depend on target: It looks like even though the target is not Node, I should be setting But with that it looks like the only documented option in Rsbuild is to use CJS output instead of ESM output is setting Finally, something which is completely not documented as far as I can tell, and which doesnʼt seem like it should work: even though I do not have Rslib installed at all, setting Are any of these the right way to force CJS? |
Replies: 3 comments 2 replies
|
(As a side note, I find everything about CJS vs ESM more confusing than I should and always need to look up details, so itʼs not impossible Iʼm confused somewhere, but saying that the CJS output is not a module seems wrong and I think it adds extra confusion. Itʼs not an ESM module, but it has |
|
I’m not very familiar with Rhino, but you could try treating it as a Node-like CommonJS target: export default {
output: {
target: 'node',
module: false,
},
splitChunks: false,
tools: {
rspack: {
output: {
asyncChunks: false,
},
},
},
};This produces a CommonJS bundle using Rslib is built on top of Rsbuild and focuses on library development. |
|
From Rsbuild core, I would not treat So for this case I would stay on the documented path: export default {
output: {
target: 'node',
module: false,
},
splitChunks: false,
tools: {
rspack: {
output: {
asyncChunks: false,
iife: false,
},
},
},
}If |
From Rsbuild core, I would not treat
lib.formatas stable Rsbuild config. The CommonJS switch in Rsbuild isoutput.module: false; for anodetarget, the output plugin maps that to Rspackoutput.library.type: 'commonjs2'here: https://github.com/web-infra-dev/rsbuild/blob/main/packages/core/src/plugins/output.ts#L131-L137. The default is also set fromoutput.target === 'node'in init config: https://github.com/web-infra-dev/rsbuild/blob/main/packages/core/src/initConfigs.ts#L142-L145.So for this case I would stay on the documented path: