mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(@vant/cli): support custom script extentions (#10624)
* feat(@vant/cli): support custom script extentions * fix: extensionsMap
This commit is contained in:
parent
0c0191332a
commit
173a364dae
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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}`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user