Skip to content

Commit d588656

Browse files
authored
Merge pull request #18 from luo3house/fix-ext
2 parents 4225953 + 2413bf5 commit d588656

File tree

2 files changed

+2933
-2744
lines changed

2 files changed

+2933
-2744
lines changed

packages/cli/src/config/vite.package.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@ export function getViteConfigForPackage({
3737
entry,
3838
formats: [format],
3939
fileName: (fmt: string) => {
40+
const isModulePkg = pkgJSON.type === 'module';
41+
const isESMFile = /esm?/.test(fmt);
42+
const ext = (function () {
43+
if ((isModulePkg && isESMFile) || (!isModulePkg && !isESMFile)) {
44+
return 'js';
45+
} else {
46+
return isESMFile ? 'mjs' : 'cjs';
47+
}
48+
})();
4049
const suffix = fmt === 'umd' ? '' : `.${fmt}`;
41-
return minify ? `${name}${suffix}.min.js` : `${name}${suffix}.js`;
50+
return minify ? `${name}${suffix}.min.${ext}` : `${name}${suffix}.${ext}`;
4251
},
4352
},
4453
cssTarget: ['chrome61'],

0 commit comments

Comments
 (0)