Skip to content

Commit c0750fd

Browse files
committed
Revert "fix: remove renaming of cjs files"
This reverts commit 420a7b4.
1 parent 2188a34 commit c0750fd

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

rollup.config.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resolve, dirname } from 'path';
1+
import { resolve, extname, dirname } from 'path';
22
import { fileURLToPath } from 'url'
33

44
import pkg from './package.json' with { type: 'json' }
@@ -15,6 +15,25 @@ import { babel } from '@rollup/plugin-babel'
1515

1616
const __dirname = dirname(fileURLToPath(import.meta.url))
1717

18+
function renameJsToCjs() {
19+
return {
20+
name: 'rename-js-to-cjs',
21+
generateBundle(options, bundle) {
22+
for (const [fileName, file] of Object.entries(bundle)) {
23+
if (file.type === 'chunk' && extname(fileName) === '.js') {
24+
const newFileName = fileName.replace(/\.js$/, '.cjs');
25+
26+
// Emit new file with updated name and same code
27+
this.emitFile({ type: 'asset', fileName: newFileName, source: file.code });
28+
29+
// Remove old .js entry
30+
delete bundle[fileName];
31+
}
32+
}
33+
},
34+
};
35+
}
36+
1837
const baseConfig = {
1938
input: 'dist/esm-raw/index.js',
2039
output: {
@@ -67,7 +86,8 @@ const cjsConfig = {
6786
preventAssignment: true,
6887
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
6988
__VERSION__: JSON.stringify(pkg.version),
70-
})
89+
}),
90+
renameJsToCjs()
7191
],
7292
}
7393

0 commit comments

Comments
 (0)