mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
Fix: Programmatic module.exports addition for named and default exports in CJS (#1460)
* experimental export patch patches the base index file to export the default as classic node cjs module * refactor * add semi Co-authored-by: daishi <daishi@axlight.com>
This commit is contained in:
parent
d53f92d827
commit
e3d738f385
@ -75,10 +75,16 @@ function createESMConfig(input, output) {
|
||||
}
|
||||
}
|
||||
|
||||
function createCommonJSConfig(input, output) {
|
||||
function createCommonJSConfig(input, output, options) {
|
||||
return {
|
||||
input,
|
||||
output: { file: `${output}.js`, format: 'cjs' },
|
||||
output: {
|
||||
file: `${output}.js`,
|
||||
format: 'cjs',
|
||||
outro: options.addModuleExport
|
||||
? 'module.exports = exports.default; Object.assign(exports.default, exports);'
|
||||
: '',
|
||||
},
|
||||
external,
|
||||
plugins: [
|
||||
alias({
|
||||
@ -166,7 +172,9 @@ module.exports = function (args) {
|
||||
}
|
||||
return [
|
||||
...(c === 'index' ? [createDeclarationConfig(`src/${c}.ts`, 'dist')] : []),
|
||||
createCommonJSConfig(`src/${c}.ts`, `dist/${c}`),
|
||||
createCommonJSConfig(`src/${c}.ts`, `dist/${c}`, {
|
||||
addModuleExport: c === 'index',
|
||||
}),
|
||||
createESMConfig(`src/${c}.ts`, `dist/esm/${c}.js`),
|
||||
createESMConfig(`src/${c}.ts`, `dist/esm/${c}.mjs`),
|
||||
createUMDConfig(`src/${c}.ts`, `dist/umd/${c}`, 'development'),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user