mirror of
https://github.com/youzan/vant.git
synced 2025-10-16 16:04:04 +00:00
feat(@vant/cli): vant config become esm
This commit is contained in:
@@ -1,5 +1,23 @@
|
||||
# 更新日志
|
||||
|
||||
## v4.0.0-rc.3
|
||||
|
||||
### 不兼容更新
|
||||
|
||||
- 支持的 node 版本范围提升到 `^14.16.0 || >=16.0.0`
|
||||
- babel preset 添加了 `cjs` 后缀,现在需要通过 `@vant/cli/preset.cjs` 引入
|
||||
- vant.config.js 重命名为 `vant.config.mjs`,由 commonJs 变更为 ESModule 格式
|
||||
|
||||
### Features
|
||||
|
||||
- 新增 build.configureWebpack 配置项
|
||||
|
||||
### 依赖升级
|
||||
|
||||
对以下依赖进行了大版本升级:
|
||||
|
||||
- eslint v8
|
||||
|
||||
## v4.0.0-beta.6
|
||||
|
||||
### 不兼容更新
|
||||
|
@@ -2,7 +2,7 @@ const { join, dirname } = require('path');
|
||||
const { existsSync } = require('fs');
|
||||
|
||||
function findRootDir(dir) {
|
||||
if (existsSync(join(dir, 'vant.config.js'))) {
|
||||
if (existsSync(join(dir, 'vant.config.mjs'))) {
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# 配置指南
|
||||
|
||||
- [配置指南](#)
|
||||
- [vant.config.js](#vantconfigjs)
|
||||
- [vant.config.mjs](#vantconfigmjs)
|
||||
- [name](#name)
|
||||
- [build.css](#buildcss)
|
||||
- [build.site.publicPath](#buildsitepublicpath)
|
||||
@@ -25,12 +25,12 @@
|
||||
- [默认配置](#-3)
|
||||
- [browserslist](#browserslist)
|
||||
|
||||
## vant.config.js
|
||||
## vant.config.mjs
|
||||
|
||||
`vant.config.js`中包含了`vant-cli`的打包配置和文档站点配置,请创建此文件并置于项目根目录下。下面是一份基本配置的示例:
|
||||
`vant.config.mjs` 中包含了 `vant-cli` 的打包配置和文档站点配置,请创建此文件并置于项目根目录下。下面是一份基本配置的示例:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
export default {
|
||||
// 组件库名称
|
||||
name: 'demo-ui',
|
||||
// 构建配置
|
||||
|
@@ -15,7 +15,7 @@ project
|
||||
│ └─ changelog.md # 更新日志
|
||||
│
|
||||
├─ babel.config.js # Babel 配置文件
|
||||
├─ vant.config.js # Vant Cli 配置文件
|
||||
├─ vant.config.mjs # Vant Cli 配置文件
|
||||
├─ package.json
|
||||
└─ README.md
|
||||
```
|
||||
|
@@ -8,7 +8,7 @@
|
||||
"vant-cli": "./bin.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.17.0 || >=16.0.0"
|
||||
"node": "^14.16.0 || >=16.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
@@ -81,7 +81,7 @@
|
||||
"postcss-load-config": "^3.1.0",
|
||||
"prettier": "^2.4.1",
|
||||
"release-it": "^14.11.6",
|
||||
"stylelint": "^14.0.1",
|
||||
"stylelint": "^13.0.0",
|
||||
"transliteration": "^2.2.0",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.4.4",
|
||||
|
@@ -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