akfun 5.1.15 → 5.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +342 -215
- package/module/main.js +1 -1
- package/package.json +15 -15
- package/src/build.js +3 -8
- package/src/build2esm.js +13 -15
- package/src/config/babel.config.js +6 -3
- package/src/config/index.js +12 -10
- package/src/config/rollup.config.js +15 -6
- package/src/dev-server.js +3 -9
- package/src/initData/akfun-package.json +14 -10
- package/src/initData/config/babel.config.js +3 -1
- package/src/manage/ConfigManager.js +16 -18
- package/src/utils/configValidator.js +10 -15
- package/src/webpack/loaderUtils.js +30 -20
- package/src/webpack/vue-loader.conf.js +2 -12
- package/src/webpack/webpack.base.conf.js +55 -15
- package/src/webpack/webpack.dev.conf.js +9 -14
- package/src/webpack/webpack.library.conf.js +7 -12
- package/src/webpack/webpack.prod.conf.js +9 -14
package/module/main.js
CHANGED
|
@@ -13,7 +13,7 @@ const aliBOS = require('../src/oss/aliBos.js');
|
|
|
13
13
|
const baiduBOS = require('../src/oss/baiduBos.js');
|
|
14
14
|
|
|
15
15
|
// 新增:配置管理和环境管理
|
|
16
|
-
const configManager = require('../src/
|
|
16
|
+
const configManager = require('../src/manage/ConfigManager');
|
|
17
17
|
const { validateConfig } = require('../src/utils/configValidator');
|
|
18
18
|
|
|
19
19
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akfun",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.17",
|
|
4
4
|
"description": "前端脚手架:支持Vue技术栈和react技术栈",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"前端工程",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@babel/cli": "^7.17.0",
|
|
53
53
|
"@babel/core": "^7.17.0",
|
|
54
|
+
"@babel/polyfill": "^7.10.1",
|
|
54
55
|
"@babel/eslint-parser": "^7.17.0",
|
|
55
56
|
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
56
57
|
"@babel/plugin-proposal-decorators": "^7.17.0",
|
|
@@ -62,21 +63,21 @@
|
|
|
62
63
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
63
64
|
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
|
64
65
|
"@babel/plugin-transform-runtime": "^7.27.1",
|
|
65
|
-
"@babel/polyfill": "^7.10.1",
|
|
66
66
|
"@babel/runtime": "^7.27.1",
|
|
67
67
|
"@babel/preset-env": "^7.16.11",
|
|
68
68
|
"@babel/preset-react": "^7.16.7",
|
|
69
69
|
"@babel/preset-typescript": "^7.16.7",
|
|
70
70
|
"@babel/register": "^7.17.0",
|
|
71
71
|
"@mapbox/stylelint-processor-arbitrary-tags": "^0.4.0",
|
|
72
|
-
"@rollup/plugin-alias": "^
|
|
73
|
-
"@rollup/plugin-babel": "^
|
|
74
|
-
"@rollup/plugin-commonjs": "^
|
|
75
|
-
"@rollup/plugin-image": "^
|
|
72
|
+
"@rollup/plugin-alias": "^5.1.1",
|
|
73
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
74
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
75
|
+
"@rollup/plugin-image": "^3.0.3",
|
|
76
76
|
"@svgr/rollup": "^8.1.0",
|
|
77
|
-
"@rollup/plugin-json": "^
|
|
78
|
-
"@rollup/plugin-node-resolve": "^
|
|
79
|
-
"@rollup/plugin-typescript": "^
|
|
77
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
78
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
79
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
80
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
80
81
|
"@svgr/webpack": "^6.2.1",
|
|
81
82
|
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
82
83
|
"@typescript-eslint/parser": "^5.10.2",
|
|
@@ -129,12 +130,11 @@
|
|
|
129
130
|
"progress-bar-webpack-plugin": "^2.1.0",
|
|
130
131
|
"qs": "^6.10.3",
|
|
131
132
|
"rimraf": "^3.0.2",
|
|
132
|
-
"rollup": "^
|
|
133
|
-
"rollup-plugin-node-externals": "^
|
|
133
|
+
"rollup": "^4.53.3",
|
|
134
|
+
"rollup-plugin-node-externals": "^8.1.2",
|
|
134
135
|
"rollup-plugin-postcss": "^4.0.2",
|
|
135
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
136
136
|
"rollup-plugin-vue": "^6.0.0",
|
|
137
|
-
"sass": "^1.
|
|
137
|
+
"sass": "^1.94.2",
|
|
138
138
|
"sass-loader": "^12.4.0",
|
|
139
139
|
"less": "^4.1.3",
|
|
140
140
|
"less-loader": "^11.0.0",
|
|
@@ -175,8 +175,8 @@
|
|
|
175
175
|
"prettier": "^2.5.1"
|
|
176
176
|
},
|
|
177
177
|
"engines": {
|
|
178
|
-
"node": ">=
|
|
179
|
-
"npm": ">=
|
|
178
|
+
"node": ">= 16.0.0",
|
|
179
|
+
"npm": ">= 8.0.0"
|
|
180
180
|
},
|
|
181
181
|
"browserslist": [
|
|
182
182
|
"> 1%",
|
package/src/build.js
CHANGED
|
@@ -5,18 +5,13 @@ const chalk = require('chalk');
|
|
|
5
5
|
const webpack = require('webpack');
|
|
6
6
|
const { curConsoleTag } = require('./utils/akfunParams');
|
|
7
7
|
const checkVersion = require('./check-versions');
|
|
8
|
-
const
|
|
9
|
-
const defaultConfig = require('./config/default.config');
|
|
10
|
-
const deepMergeConfig = require('./utils/deepMergeConfig');
|
|
8
|
+
const getProjectConfig = require('./config/index'); // 用于获取当前项目配置文件
|
|
11
9
|
|
|
12
10
|
// 构建脚本:一般用于构建生产环境的代码
|
|
13
11
|
module.exports = function (BuildType, akfunConfig, _consoleTag, callbackFunc) {
|
|
14
12
|
const consoleTag = _consoleTag || curConsoleTag;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// 参数中的config配置优先级最高
|
|
18
|
-
config = deepMergeConfig(defaultConfig, akfunConfig);
|
|
19
|
-
}
|
|
13
|
+
// 获取项目配置文件
|
|
14
|
+
let config = getProjectConfig(akfunConfig);
|
|
20
15
|
let curEnvConfig = config.build;
|
|
21
16
|
// 检查当前npm版本号是否匹配
|
|
22
17
|
checkVersion();
|
package/src/build2esm.js
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
const ora = require('ora');
|
|
2
2
|
const rollup = require('rollup');
|
|
3
|
-
const { terser } = require('rollup
|
|
4
|
-
const
|
|
5
|
-
const defaultConfig = require('./config/default.config');
|
|
3
|
+
const { terser } = require('@rollup/plugin-terser'); // 压缩
|
|
4
|
+
const getProjectConfig = require('./config/index'); // 用于获取当前项目配置文件
|
|
6
5
|
const rollupConfig = require('./config/rollup.config'); // rollup的配置文件
|
|
7
6
|
const { isArray, isObject } = require('./utils/typeof');
|
|
8
7
|
const { curConsoleTag } = require('./utils/akfunParams');
|
|
9
|
-
const deepMergeConfig = require('./utils/deepMergeConfig');
|
|
10
8
|
|
|
11
9
|
async function build2esmFunc(options, curConfig) {
|
|
12
10
|
// create a bundle
|
|
13
11
|
const bundle = await rollup.rollup({
|
|
14
12
|
input: options.input,
|
|
15
|
-
external: options.externals,
|
|
13
|
+
external: options.external || options.externals, // 兼容新旧两种写法
|
|
16
14
|
plugins: options.plugins
|
|
17
15
|
});
|
|
18
16
|
|
|
19
17
|
if (isArray(options.output)) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
18
|
+
// 等待所有输出完成
|
|
19
|
+
await Promise.all(options.output.map((outputItem) => bundle.write(outputItem)));
|
|
23
20
|
} else if (isObject(options.output)) {
|
|
24
21
|
// or write the bundle to disk
|
|
25
22
|
await bundle.write(options.output);
|
|
26
23
|
}
|
|
24
|
+
|
|
25
|
+
// 关闭 bundle 以释放资源
|
|
26
|
+
await bundle.close();
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// 构建脚本:一般用于构建生产环境的代码
|
|
30
30
|
module.exports = function (fileName, akfunConfig, _consoleTag) {
|
|
31
31
|
const consoleTag = _consoleTag || curConsoleTag;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
config = deepMergeConfig(defaultConfig, akfunConfig);
|
|
36
|
-
}
|
|
32
|
+
// 获取项目配置文件
|
|
33
|
+
let config = getProjectConfig(akfunConfig);
|
|
34
|
+
|
|
37
35
|
const spinner = ora(`${consoleTag}开启esm模块构建能力...`).start();
|
|
38
36
|
const curRollupConfig = rollupConfig(fileName, config); // 默认配置
|
|
39
37
|
const build2esm = config.build2esm; // 用户的项目配置
|
|
@@ -60,8 +58,8 @@ module.exports = function (fileName, akfunConfig, _consoleTag) {
|
|
|
60
58
|
externals = externals.concat(Object.keys(build2esmExternal));
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
// 添加到 rollup
|
|
64
|
-
curRollupConfig.
|
|
61
|
+
// 添加到 rollup 配置中(rollup 使用 external 而不是 externals)
|
|
62
|
+
curRollupConfig.external = externals;
|
|
65
63
|
|
|
66
64
|
if (build2esm && build2esm.output) {
|
|
67
65
|
curRollupConfig.output = build2esm.output;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
+
sourceType: 'module', // 明确指定源类型为 ES 模块,以支持 import/export 语法
|
|
2
3
|
presets: [
|
|
3
4
|
[
|
|
4
5
|
'@babel/preset-env',
|
|
5
6
|
{
|
|
6
7
|
loose: true,
|
|
7
8
|
modules: false, // 是否启用将ES6模块语法转换为其他模块类型的功能,当前设置为false,以便webpack进行tree shaking。
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/*
|
|
10
|
+
备注:后续升级babel版本时,再启用此配置
|
|
11
|
+
useBuiltIns: 'usage', // 按需引入 polyfill,替代 @babel/polyfill
|
|
12
|
+
corejs: 3, // 使用 core-js 3.x 版本
|
|
13
|
+
*/
|
|
11
14
|
}
|
|
12
15
|
],
|
|
13
16
|
['@babel/preset-react'],
|
package/src/config/index.js
CHANGED
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
* 配置入口文件
|
|
3
3
|
* 统一加载和管理 AKFun 配置
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
// 使用新的配置管理器
|
|
7
6
|
const configManager = require('../manage/ConfigManager');
|
|
8
7
|
|
|
9
|
-
// 自动加载用户配置文件
|
|
10
|
-
configManager.autoLoadConfig();
|
|
11
|
-
|
|
12
|
-
// 合并配置
|
|
13
|
-
const mergedConfig = configManager.mergeConfig();
|
|
14
|
-
|
|
15
8
|
// 导出合并后的配置(向后兼容)
|
|
16
|
-
module.exports =
|
|
9
|
+
module.exports = (akfunConfig) => {
|
|
10
|
+
if (!akfunConfig) {
|
|
11
|
+
// 自动加载用户配置文件
|
|
12
|
+
configManager.autoLoadConfig();
|
|
13
|
+
}
|
|
14
|
+
// 合并配置
|
|
15
|
+
const mergedConfig = configManager.mergeConfig(akfunConfig);
|
|
16
|
+
|
|
17
|
+
// 校验当前项目配置
|
|
18
|
+
configManager.validateConfig();
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
return mergedConfig;
|
|
21
|
+
};
|
|
@@ -7,7 +7,7 @@ const commonjs = require('@rollup/plugin-commonjs'); // 识别cmd模块
|
|
|
7
7
|
const vue = require('rollup-plugin-vue');
|
|
8
8
|
const json = require('@rollup/plugin-json'); // 识别json类型文件
|
|
9
9
|
const image = require('@rollup/plugin-image'); // 图片处理器
|
|
10
|
-
const
|
|
10
|
+
const terser = require('@rollup/plugin-terser'); // 压缩
|
|
11
11
|
const alias = require('@rollup/plugin-alias'); // 简写配置
|
|
12
12
|
// css相关处理器
|
|
13
13
|
const postcss = require('rollup-plugin-postcss');
|
|
@@ -21,7 +21,7 @@ const postcssPresetEnv = require('postcss-preset-env');
|
|
|
21
21
|
const cssnano = require('cssnano');
|
|
22
22
|
// 处理svg文件
|
|
23
23
|
const svgr = require('@svgr/rollup');
|
|
24
|
-
const {
|
|
24
|
+
const { nodeExternals } = require('rollup-plugin-node-externals');
|
|
25
25
|
const { resolveToCurrentRoot, resolveToCurrentDist } = require('../utils/pathUtils'); // 统一路径解析
|
|
26
26
|
const babelConfig = require('./babel.config'); // Babel的配置文件
|
|
27
27
|
const projectConfig = require('./index'); // 引入当前项目配置文件
|
|
@@ -57,21 +57,30 @@ module.exports = function (fileName, akfunConfig) {
|
|
|
57
57
|
input: rollupInput,
|
|
58
58
|
plugins: [
|
|
59
59
|
alias({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
entries: Object.entries(curConfig.webpack.resolve.alias || {}).map(
|
|
61
|
+
([find, replacement]) => ({
|
|
62
|
+
find,
|
|
63
|
+
replacement
|
|
64
|
+
})
|
|
65
|
+
)
|
|
63
66
|
}),
|
|
64
67
|
/**
|
|
65
68
|
* excludeList(在akfun.config.js中配置)
|
|
66
69
|
* 设置打包中应该排除的依赖
|
|
67
70
|
*/
|
|
68
|
-
|
|
71
|
+
nodeExternals({
|
|
69
72
|
include: build2esm.excludeList || []
|
|
70
73
|
// exclude: ['./**', '../**'], // 排除所有相对路径模块
|
|
71
74
|
// deps: true, // 只标记 node_modules 中的依赖
|
|
72
75
|
// devDeps: false, // 不标记 devDependencies
|
|
73
76
|
// peerDeps: true, // 标记 peerDependencies
|
|
74
77
|
}),
|
|
78
|
+
/**
|
|
79
|
+
* nodeResolve 插件用于解析模块路径
|
|
80
|
+
* extensions: 默认识别的文件后缀列表
|
|
81
|
+
* 默认值(来自 webpack.resolve.extensions): ['.js', '.jsx', '.ts', '.tsx', '.vue', '.json']
|
|
82
|
+
* 如果不配置此插件,Rollup 默认只识别 .js 和 .mjs 文件
|
|
83
|
+
*/
|
|
75
84
|
nodeResolve({
|
|
76
85
|
extensions: curConfig.webpack.resolve.extensions
|
|
77
86
|
}),
|
package/src/dev-server.js
CHANGED
|
@@ -9,21 +9,15 @@ const portfinder = require('portfinder');
|
|
|
9
9
|
const checkVersion = require('./check-versions');
|
|
10
10
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
11
11
|
const { resolve } = require('./utils/pathUtils');
|
|
12
|
-
//
|
|
13
|
-
const projectConfig = require('./config/index');
|
|
14
|
-
const defaultConfig = require('./config/default.config');
|
|
12
|
+
const getProjectConfig = require('./config/index'); // 用于获取当前项目配置文件
|
|
15
13
|
const getDevWebpackConfig = require('./webpack/webpack.dev.conf');
|
|
16
|
-
const deepMergeConfig = require('./utils/deepMergeConfig');
|
|
17
14
|
const { curConsoleTag } = require('./utils/akfunParams');
|
|
18
15
|
|
|
19
16
|
// 构建脚本:一般用于构建开发环境的代码(包含热更新、接口代理等功能)
|
|
20
17
|
module.exports = function (akfunConfig, _consoleTag) {
|
|
21
18
|
const consoleTag = _consoleTag || curConsoleTag;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// 优先使用参数中的config配置
|
|
25
|
-
config = deepMergeConfig(defaultConfig, akfunConfig);
|
|
26
|
-
}
|
|
19
|
+
// 获取项目配置文件
|
|
20
|
+
let config = getProjectConfig(akfunConfig);
|
|
27
21
|
const curEnvConfig = config.dev;
|
|
28
22
|
// 检查当前npm版本号是否匹配
|
|
29
23
|
checkVersion();
|
|
@@ -55,18 +55,20 @@
|
|
|
55
55
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
56
56
|
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
|
57
57
|
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
58
|
-
"@babel/polyfill": "^7.10.1",
|
|
59
58
|
"@babel/preset-env": "^7.16.11",
|
|
60
59
|
"@babel/preset-react": "^7.16.7",
|
|
61
60
|
"@babel/preset-typescript": "^7.16.7",
|
|
62
61
|
"@babel/register": "^7.17.0",
|
|
63
62
|
"@mapbox/stylelint-processor-arbitrary-tags": "^0.4.0",
|
|
64
|
-
"@rollup/plugin-alias": "^
|
|
65
|
-
"@rollup/plugin-babel": "^
|
|
66
|
-
"@rollup/plugin-commonjs": "^
|
|
67
|
-
"@rollup/plugin-image": "^
|
|
68
|
-
"@rollup/plugin-json": "^
|
|
69
|
-
"@rollup/plugin-node-resolve": "^
|
|
63
|
+
"@rollup/plugin-alias": "^6.0.0",
|
|
64
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
65
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
66
|
+
"@rollup/plugin-image": "^3.0.3",
|
|
67
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
68
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
69
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
70
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
71
|
+
"@svgr/rollup": "^8.1.0",
|
|
70
72
|
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
71
73
|
"@typescript-eslint/parser": "^5.10.2",
|
|
72
74
|
"@vue/compiler-sfc": "^3.2.29",
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
"chalk": "^4.0.0",
|
|
78
80
|
"compression-webpack-plugin": "^9.2.0",
|
|
79
81
|
"connect-history-api-fallback": "^1.6.0",
|
|
82
|
+
"core-js": "^3.47.0",
|
|
80
83
|
"copy-webpack-plugin": "^10.2.4",
|
|
81
84
|
"css-loader": "^6.6.0",
|
|
82
85
|
"cssnano": "^5.0.16",
|
|
@@ -104,7 +107,7 @@
|
|
|
104
107
|
"http-proxy-middleware": "^2.0.2",
|
|
105
108
|
"inquirer": "^8.2.0",
|
|
106
109
|
"mini-css-extract-plugin": "^2.5.3",
|
|
107
|
-
"sass": "^1.
|
|
110
|
+
"sass": "^1.94.2",
|
|
108
111
|
"open": "^8.4.0",
|
|
109
112
|
"ora": "^4.0.4",
|
|
110
113
|
"params-replace-loader": "^1.1.6",
|
|
@@ -116,9 +119,10 @@
|
|
|
116
119
|
"progress-bar-webpack-plugin": "^2.1.0",
|
|
117
120
|
"qs": "^6.10.3",
|
|
118
121
|
"rimraf": "^3.0.2",
|
|
119
|
-
"rollup": "^
|
|
122
|
+
"rollup": "^4.53.3",
|
|
123
|
+
"rollup-plugin-jsx": "^1.0.3",
|
|
124
|
+
"rollup-plugin-node-externals": "^8.1.2",
|
|
120
125
|
"rollup-plugin-postcss": "^4.0.2",
|
|
121
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
122
126
|
"rollup-plugin-vue": "^6.0.0",
|
|
123
127
|
"sass-loader": "^12.4.0",
|
|
124
128
|
"sass-resources-loader": "^2.2.4",
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
module.
|
|
1
|
+
module.exports = {
|
|
2
2
|
presets: [
|
|
3
3
|
[
|
|
4
4
|
'@babel/preset-env',
|
|
5
5
|
{
|
|
6
6
|
loose: false,
|
|
7
7
|
modules: false,
|
|
8
|
+
useBuiltIns: 'usage', // 按需引入 polyfill,替代 @babel/polyfill
|
|
9
|
+
corejs: 3, // 使用 core-js 3.x 版本
|
|
8
10
|
targets: {
|
|
9
11
|
browsers: ['> 1%', 'last 2 versions', 'not ie <= 8']
|
|
10
12
|
}
|
|
@@ -58,9 +58,7 @@ class ConfigManager {
|
|
|
58
58
|
* 按优先级查找:akfun.config.js -> akfun.config.json
|
|
59
59
|
* @returns {Object|null}
|
|
60
60
|
*/
|
|
61
|
-
autoLoadConfig() {
|
|
62
|
-
const configFiles = ['akfun.config.js', 'akfun.config.json', '.akfunrc.js', '.akfunrc.json'];
|
|
63
|
-
|
|
61
|
+
autoLoadConfig(configFiles = ['akfun.config.js', 'akfun.config.json', '.akfunrc.js', '.akfunrc.json']) {
|
|
64
62
|
for (const configFile of configFiles) {
|
|
65
63
|
const configPath = path.resolve(process.cwd(), configFile);
|
|
66
64
|
if (fs.existsSync(configPath)) {
|
|
@@ -68,7 +66,7 @@ class ConfigManager {
|
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
console.log(chalk.gray('
|
|
69
|
+
console.log(chalk.gray(' 未找到项目配置文件,使用默认配置'));
|
|
72
70
|
return null;
|
|
73
71
|
}
|
|
74
72
|
|
|
@@ -150,12 +148,12 @@ class ConfigManager {
|
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
/**
|
|
153
|
-
*
|
|
151
|
+
* 验证当前项目的配置(仅验证 userConfig 中的配置)
|
|
154
152
|
* @returns {Object} 验证后的配置
|
|
155
153
|
*/
|
|
156
154
|
validateConfig() {
|
|
157
|
-
if (!this.
|
|
158
|
-
this.
|
|
155
|
+
if (!this.userConfig) {
|
|
156
|
+
return this.userConfig;
|
|
159
157
|
}
|
|
160
158
|
|
|
161
159
|
try {
|
|
@@ -165,7 +163,7 @@ class ConfigManager {
|
|
|
165
163
|
// 如果有配置验证器,使用它
|
|
166
164
|
try {
|
|
167
165
|
const { validateConfig } = require('../utils/configValidator');
|
|
168
|
-
return validateConfig(this.
|
|
166
|
+
return validateConfig(this.userConfig);
|
|
169
167
|
} catch (error) {
|
|
170
168
|
// 如果配置验证器不存在或出错,只进行基础验证
|
|
171
169
|
if (process.env.AKFUN_DEBUG) {
|
|
@@ -173,7 +171,7 @@ class ConfigManager {
|
|
|
173
171
|
}
|
|
174
172
|
}
|
|
175
173
|
|
|
176
|
-
return this.
|
|
174
|
+
return this.userConfig;
|
|
177
175
|
} catch (error) {
|
|
178
176
|
console.error(chalk.red('\n❌ 配置验证失败:'));
|
|
179
177
|
console.error(chalk.red(` ${error.message}\n`));
|
|
@@ -186,23 +184,23 @@ class ConfigManager {
|
|
|
186
184
|
* @private
|
|
187
185
|
*/
|
|
188
186
|
_validateBasicConfig() {
|
|
189
|
-
const config = this.
|
|
187
|
+
const config = this.userConfig;
|
|
190
188
|
|
|
191
189
|
// 验证必需的配置项
|
|
192
|
-
if (
|
|
193
|
-
throw new Error('dev
|
|
190
|
+
if (config.dev && typeof config.dev !== 'object') {
|
|
191
|
+
throw new Error('dev 配置格式错误');
|
|
194
192
|
}
|
|
195
193
|
|
|
196
|
-
if (
|
|
197
|
-
throw new Error('build
|
|
194
|
+
if (config.build && typeof config.build !== 'object') {
|
|
195
|
+
throw new Error('build 配置格式错误');
|
|
198
196
|
}
|
|
199
197
|
|
|
200
|
-
if (
|
|
201
|
-
throw new Error('webpack
|
|
198
|
+
if (config.webpack && typeof config.webpack !== 'object') {
|
|
199
|
+
throw new Error('webpack 配置格式错误');
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
// 验证端口号
|
|
205
|
-
if (config.dev.port) {
|
|
203
|
+
if (config.dev && config.dev.port) {
|
|
206
204
|
const port = parseInt(config.dev.port, 10);
|
|
207
205
|
if (isNaN(port) || port < 1 || port > 65535) {
|
|
208
206
|
throw new Error('dev.port 必须是 1-65535 之间的数字');
|
|
@@ -210,7 +208,7 @@ class ConfigManager {
|
|
|
210
208
|
}
|
|
211
209
|
|
|
212
210
|
// 验证路径
|
|
213
|
-
if (config.build.assetsRoot) {
|
|
211
|
+
if (config.build && config.build.assetsRoot) {
|
|
214
212
|
const assetsRoot = config.build.assetsRoot;
|
|
215
213
|
if (typeof assetsRoot !== 'string') {
|
|
216
214
|
throw new Error('build.assetsRoot 必须是字符串类型的路径');
|
|
@@ -35,7 +35,7 @@ class ConfigValidator {
|
|
|
35
35
|
|
|
36
36
|
// 输出警告
|
|
37
37
|
if (this.warnings.length > 0) {
|
|
38
|
-
console.log(chalk.yellow('\n⚠️
|
|
38
|
+
console.log(chalk.yellow('\n⚠️ 配置异常提示:'));
|
|
39
39
|
this.warnings.forEach((warning) => {
|
|
40
40
|
console.log(chalk.yellow(` - ${warning}`));
|
|
41
41
|
});
|
|
@@ -81,23 +81,18 @@ class ConfigValidator {
|
|
|
81
81
|
* @private
|
|
82
82
|
*/
|
|
83
83
|
_validateWebpack(webpack) {
|
|
84
|
-
if (!webpack) {
|
|
85
|
-
this.errors.push('webpack 配置缺失');
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
84
|
// 验证 entry
|
|
90
|
-
if (webpack.entry !== undefined) {
|
|
85
|
+
if (webpack && webpack.entry !== undefined) {
|
|
91
86
|
this._validateEntry(webpack.entry);
|
|
92
87
|
}
|
|
93
88
|
|
|
94
89
|
// 验证 resolve
|
|
95
|
-
if (webpack.resolve) {
|
|
90
|
+
if (webpack && webpack.resolve) {
|
|
96
91
|
this._validateResolve(webpack.resolve);
|
|
97
92
|
}
|
|
98
93
|
|
|
99
94
|
// 验证 externals
|
|
100
|
-
if (webpack.externals !== undefined) {
|
|
95
|
+
if (webpack && webpack.externals !== undefined) {
|
|
101
96
|
const validTypes = ['object', 'string', 'function'];
|
|
102
97
|
if (!validTypes.includes(typeof webpack.externals)) {
|
|
103
98
|
this.errors.push('webpack.externals 类型不正确');
|
|
@@ -105,14 +100,14 @@ class ConfigValidator {
|
|
|
105
100
|
}
|
|
106
101
|
|
|
107
102
|
// 验证 sassResources
|
|
108
|
-
if (webpack.sassResources !== undefined) {
|
|
103
|
+
if (webpack && webpack.sassResources !== undefined) {
|
|
109
104
|
if (!Array.isArray(webpack.sassResources)) {
|
|
110
105
|
this.errors.push('webpack.sassResources 必须是数组');
|
|
111
106
|
}
|
|
112
107
|
}
|
|
113
108
|
|
|
114
109
|
// 验证 babelPlugins
|
|
115
|
-
if (webpack.babelPlugins !== undefined) {
|
|
110
|
+
if (webpack && webpack.babelPlugins !== undefined) {
|
|
116
111
|
const validTypes = ['function', 'object'];
|
|
117
112
|
const type = Array.isArray(webpack.babelPlugins) ? 'object' : typeof webpack.babelPlugins;
|
|
118
113
|
if (!validTypes.includes(type)) {
|
|
@@ -121,12 +116,12 @@ class ConfigValidator {
|
|
|
121
116
|
}
|
|
122
117
|
|
|
123
118
|
// 验证 moduleRules
|
|
124
|
-
if (webpack.moduleRules !== undefined && !Array.isArray(webpack.moduleRules)) {
|
|
119
|
+
if (webpack && webpack.moduleRules !== undefined && !Array.isArray(webpack.moduleRules)) {
|
|
125
120
|
this.errors.push('webpack.moduleRules 必须是数组');
|
|
126
121
|
}
|
|
127
122
|
|
|
128
123
|
// 验证 plugins
|
|
129
|
-
if (webpack.plugins !== undefined && !Array.isArray(webpack.plugins)) {
|
|
124
|
+
if (webpack && webpack.plugins !== undefined && !Array.isArray(webpack.plugins)) {
|
|
130
125
|
this.errors.push('webpack.plugins 必须是数组');
|
|
131
126
|
}
|
|
132
127
|
}
|
|
@@ -384,9 +379,9 @@ class ConfigValidator {
|
|
|
384
379
|
return;
|
|
385
380
|
}
|
|
386
381
|
|
|
387
|
-
if (portNum < 1024 && process.platform
|
|
382
|
+
if (portNum < 1024 && process.platform === 'win32') {
|
|
388
383
|
this.warnings.push(
|
|
389
|
-
`${fieldName} (${portNum}) 小于 1024
|
|
384
|
+
`${fieldName} (${portNum}) 小于 1024,在 Windows 系统上可能需要管理员权限。`
|
|
390
385
|
);
|
|
391
386
|
}
|
|
392
387
|
}
|