Skip to content

Commit 56a6ee5

Browse files
committed
Fix extensions of built files in CJS format
1 parent db784cf commit 56a6ee5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

scripts/build.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,23 @@ build({
4141

4242
build({
4343
format: 'cjs',
44+
bundle: true,
4445
outExtension: { '.js': '.cjs' },
46+
plugins: [
47+
// @see https://github.com/evanw/esbuild/issues/622#issuecomment-769462611
48+
{
49+
name: 'change-extension-to-cjs',
50+
setup(builder) {
51+
// eslint-disable-next-line consistent-return
52+
builder.onResolve({ filter: /.*/ }, (args) => {
53+
if (args.importer) {
54+
return {
55+
path: args.path.replace(/\.js$/, '.cjs'),
56+
external: true,
57+
};
58+
}
59+
});
60+
},
61+
},
62+
],
4563
});

0 commit comments

Comments
 (0)