feat(@vant/cli): support custom script extentions (#10624)

* feat(@vant/cli): support custom script extentions

* fix: extensionsMap
This commit is contained in:
neverland 2022-05-22 19:57:16 +08:00 committed by GitHub
parent 0c0191332a
commit 173a364dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import fse from 'fs-extra';
import babel from '@babel/core'; import babel from '@babel/core';
import esbuild, { type Format } from 'esbuild'; import esbuild, { type Format } from 'esbuild';
import { sep } from 'path'; 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 { replaceCSSImportExt } from '../common/css.js';
import { replaceScriptImportExt } from './get-deps.js'; import { replaceScriptImportExt } from './get-deps.js';
@ -50,7 +50,9 @@ export async function compileScript(
({ code } = esbuildResult); ({ code } = esbuildResult);
const jsFilePath = replaceExt(filePath, '.js'); const extensionMap = getVantConfig().build?.extensions;
const extension = extensionMap?.[format] || '.js';
const jsFilePath = replaceExt(filePath, extension);
removeSync(filePath); removeSync(filePath);
outputFileSync(jsFilePath, code); outputFileSync(jsFilePath, code);
} }

View File

@ -14,7 +14,9 @@ export function getViteConfigForPackage({
}): InlineConfig { }): InlineConfig {
setBuildTarget('package'); setBuildTarget('package');
const { name } = getVantConfig(); const { name, build } = getVantConfig();
const entryExtension = build?.extensions?.esm || '.js';
const entry = join(ES_DIR, `index${entryExtension}`);
return { return {
root: CWD, root: CWD,
@ -24,7 +26,7 @@ export function getViteConfigForPackage({
build: { build: {
lib: { lib: {
name, name,
entry: join(ES_DIR, 'index.js'), entry,
formats, formats,
fileName: (format: string) => { fileName: (format: string) => {
const suffix = format === 'umd' ? '' : `.${format}`; const suffix = format === 'umd' ? '' : `.${format}`;