mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 16:44:21 +00:00
feat(@vant/cli): vant config become esm
This commit is contained in:
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
|
||||
import { join, dirname, isAbsolute } from 'path';
|
||||
|
||||
function findRootDir(dir: string): string {
|
||||
if (existsSync(join(dir, 'vant.config.js'))) {
|
||||
if (existsSync(join(dir, 'vant.config.mjs'))) {
|
||||
return dir;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export const LIB_DIR = join(ROOT, 'lib');
|
||||
export const DOCS_DIR = join(ROOT, 'docs');
|
||||
export const VETUR_DIR = join(ROOT, 'vetur');
|
||||
export const SITE_DIST_DIR = join(ROOT, 'site-dist');
|
||||
export const VANT_CONFIG_FILE = join(ROOT, 'vant.config.js');
|
||||
export const VANT_CONFIG_FILE = join(ROOT, 'vant.config.mjs');
|
||||
export const PACKAGE_JSON_FILE = join(ROOT, 'package.json');
|
||||
|
||||
// Relative paths
|
||||
@@ -57,17 +57,23 @@ export function getPackageJson() {
|
||||
return JSON.parse(rawJson);
|
||||
}
|
||||
|
||||
export function getVantConfig() {
|
||||
async function getVantConfigAsync() {
|
||||
const require = createRequire(import.meta.url);
|
||||
delete require.cache[VANT_CONFIG_FILE];
|
||||
|
||||
try {
|
||||
return require(VANT_CONFIG_FILE);
|
||||
return (await import(VANT_CONFIG_FILE)).default;
|
||||
} catch (err) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
const vantConfig = await getVantConfigAsync();
|
||||
|
||||
export function getVantConfig() {
|
||||
return vantConfig;
|
||||
}
|
||||
|
||||
function getSrcDir() {
|
||||
const vantConfig = getVantConfig();
|
||||
const srcDir = get(vantConfig, 'build.srcDir');
|
||||
|
@@ -2,11 +2,11 @@ import glob from 'fast-glob';
|
||||
import { join, parse } from 'path';
|
||||
import { existsSync, readFileSync, readdirSync } from 'fs';
|
||||
import {
|
||||
isDev,
|
||||
pascalize,
|
||||
getVantConfig,
|
||||
smartOutputFile,
|
||||
normalizePath,
|
||||
isDev,
|
||||
} from '../common/index.js';
|
||||
import {
|
||||
SRC_DIR,
|
||||
@@ -98,7 +98,7 @@ function genExportDocuments(items: DocumentItem[]) {
|
||||
|
||||
function genVantConfigContent() {
|
||||
const content = readFileSync(VANT_CONFIG_FILE, 'utf-8');
|
||||
return content.replace('module.exports', 'const config');
|
||||
return content.replace('export default', 'const config =');
|
||||
}
|
||||
|
||||
function genExportConfig() {
|
||||
|
Reference in New Issue
Block a user