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 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);
}

View File

@ -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}`;