mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(vant-cli): support defineOptions named (#12734)
This commit is contained in:
parent
41fb2cc9ed
commit
933e73a4f2
@ -1,15 +1,15 @@
|
|||||||
import fse from 'fs-extra';
|
import fse from 'fs-extra';
|
||||||
import { sep, join } from 'node:path';
|
import { sep, join } from 'node:path';
|
||||||
import { SRC_DIR, getVantConfig } from './constant.js';
|
import { SRC_DIR, getVantConfig } from './constant.js';
|
||||||
import { InlineConfig, loadConfigFromFile, mergeConfig } from 'vite';
|
import { type InlineConfig, loadConfigFromFile, mergeConfig } from 'vite';
|
||||||
|
|
||||||
const { lstatSync, existsSync, readdirSync, readFileSync, outputFileSync } =
|
const { lstatSync, existsSync, readdirSync, readFileSync, outputFileSync } =
|
||||||
fse;
|
fse;
|
||||||
|
|
||||||
export const EXT_REGEXP = /\.\w+$/;
|
export const EXT_REGEXP = /\.\w+$/;
|
||||||
export const SFC_REGEXP = /\.(vue)$/;
|
export const SFC_REGEXP = /\.(vue)$/;
|
||||||
export const DEMO_REGEXP = new RegExp('\\' + sep + 'demo$');
|
export const DEMO_REGEXP = new RegExp(`\\${sep}demo$`);
|
||||||
export const TEST_REGEXP = new RegExp('\\' + sep + 'test$');
|
export const TEST_REGEXP = new RegExp(`\\${sep}test$`);
|
||||||
export const ASSET_REGEXP = /\.(png|jpe?g|gif|webp|ico|jfif|svg|woff2?|ttf)$/i;
|
export const ASSET_REGEXP = /\.(png|jpe?g|gif|webp|ico|jfif|svg|woff2?|ttf)$/i;
|
||||||
export const STYLE_REGEXP = /\.(css|less|scss)$/;
|
export const STYLE_REGEXP = /\.(css|less|scss)$/;
|
||||||
export const SCRIPT_REGEXP = /\.(js|ts|jsx|tsx)$/;
|
export const SCRIPT_REGEXP = /\.(js|ts|jsx|tsx)$/;
|
||||||
@ -24,8 +24,12 @@ export function replaceExt(path: string, ext: string) {
|
|||||||
return path.replace(EXT_REGEXP, ext);
|
return path.replace(EXT_REGEXP, ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasDefaultExport(code: string) {
|
export function hasExportOrDefineOptions(code: string) {
|
||||||
return code.includes('export default') || code.includes('export { default }');
|
return (
|
||||||
|
code.includes('export default') ||
|
||||||
|
code.includes('export { default }') ||
|
||||||
|
code.includes('defineOptions')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getComponents() {
|
export function getComponents() {
|
||||||
@ -38,7 +42,7 @@ export function getComponents() {
|
|||||||
ENTRY_EXTS.some((ext) => {
|
ENTRY_EXTS.some((ext) => {
|
||||||
const path = join(SRC_DIR, dir, `index.${ext}`);
|
const path = join(SRC_DIR, dir, `index.${ext}`);
|
||||||
if (existsSync(path)) {
|
if (existsSync(path)) {
|
||||||
return hasDefaultExport(readFileSync(path, 'utf-8'));
|
return hasExportOrDefineOptions(readFileSync(path, 'utf-8'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -71,8 +75,8 @@ export function pascalize(str: string): string {
|
|||||||
|
|
||||||
export function decamelize(str: string, sep = '-') {
|
export function decamelize(str: string, sep = '-') {
|
||||||
return str
|
return str
|
||||||
.replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2')
|
.replace(/([a-z\d])([A-Z])/g, `$1${sep}$2`)
|
||||||
.replace(/([A-Z])([A-Z][a-z\d]+)/g, '$1' + sep + '$2')
|
.replace(/([A-Z])([A-Z][a-z\d]+)/g, `$1${sep}$2`)
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user