diff --git a/packages/vant-cli/src/compiler/compile-script.ts b/packages/vant-cli/src/compiler/compile-script.ts index d77a56acd..ca1dd95b0 100644 --- a/packages/vant-cli/src/compiler/compile-script.ts +++ b/packages/vant-cli/src/compiler/compile-script.ts @@ -2,7 +2,7 @@ import fse from 'fs-extra'; import babel from '@babel/core'; import esbuild, { type Format } from 'esbuild'; import { sep } from 'path'; -import { isJsx, replaceExt } from '../common/index.js'; +import { isJsx, replaceExt, getVantConfig } from '../common/index.js'; import { replaceCSSImportExt } from '../common/css.js'; import { replaceScriptImportExt } from './get-deps.js'; @@ -50,7 +50,9 @@ export async function compileScript( ({ code } = esbuildResult); - const jsFilePath = replaceExt(filePath, '.js'); + const extensionMap = getVantConfig().build?.extensions; + const extension = extensionMap?.[format] || '.js'; + const jsFilePath = replaceExt(filePath, extension); removeSync(filePath); outputFileSync(jsFilePath, code); } diff --git a/packages/vant-cli/src/config/vite.package.ts b/packages/vant-cli/src/config/vite.package.ts index 7c780e3b4..4d6f35469 100644 --- a/packages/vant-cli/src/config/vite.package.ts +++ b/packages/vant-cli/src/config/vite.package.ts @@ -14,7 +14,9 @@ export function getViteConfigForPackage({ }): InlineConfig { setBuildTarget('package'); - const { name } = getVantConfig(); + const { name, build } = getVantConfig(); + const entryExtension = build?.extensions?.esm || '.js'; + const entry = join(ES_DIR, `index${entryExtension}`); return { root: CWD, @@ -24,7 +26,7 @@ export function getViteConfigForPackage({ build: { lib: { name, - entry: join(ES_DIR, 'index.js'), + entry, formats, fileName: (format: string) => { const suffix = format === 'umd' ? '' : `.${format}`;