Skip to content

Commit e906aaa

Browse files
Merge pull request #1409 from athenacfr/fix/cjs-esm-compat
fix: bundle ESM-only deps into CJS output with Rollup
2 parents fda4c22 + 901f1b4 commit e906aaa

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

rollup.config.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,35 @@ const esmConfigs = [
8787
},
8888
];
8989

90+
const cjsConfigs = [
91+
{
92+
input: 'src/index.ts',
93+
output: {
94+
file: 'lib/index.js',
95+
format: 'cjs',
96+
exports: 'named',
97+
sourcemap: true,
98+
},
99+
plugins: getPlugins({ browser: false, outDir: 'lib' }),
100+
},
101+
{
102+
input: 'src/client/html-to-dom.ts',
103+
output: {
104+
file: 'lib/client/html-to-dom.js',
105+
format: 'cjs',
106+
exports: 'named',
107+
sourcemap: true,
108+
},
109+
plugins: getPlugins({ browser: true, outDir: 'lib/client' }),
110+
},
111+
];
112+
90113
const configs = [];
91114

115+
if (process.env.CJS === 'true') {
116+
configs.push(...cjsConfigs);
117+
}
118+
92119
if (process.env.ESM === 'true') {
93120
configs.push(...esmConfigs);
94121
}

scripts/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env bash
22

33
if [[ $1 == '--cjs' ]]; then
4-
tsc --project tsconfig.build.json
4+
tsc --project tsconfig.build.json --emitDeclarationOnly
55
find lib -type f \( -name '*.mjs*' -or -name '*.mts*' \) -delete
6+
rollup --config --failAfterWarnings --environment CJS:true
67

78
elif [[ $1 == '--esm' ]]; then
89
if [[ ! -z $(git status --porcelain src) ]]; then

0 commit comments

Comments
 (0)