akfun 5.1.16 → 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/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/config/ConfigManager');
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.16",
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",
@@ -68,7 +69,7 @@
68
69
  "@babel/preset-typescript": "^7.16.7",
69
70
  "@babel/register": "^7.17.0",
70
71
  "@mapbox/stylelint-processor-arbitrary-tags": "^0.4.0",
71
- "@rollup/plugin-alias": "^6.0.0",
72
+ "@rollup/plugin-alias": "^5.1.1",
72
73
  "@rollup/plugin-babel": "^6.1.0",
73
74
  "@rollup/plugin-commonjs": "^29.0.0",
74
75
  "@rollup/plugin-image": "^3.0.3",
@@ -88,7 +89,6 @@
88
89
  "chalk": "^4.0.0",
89
90
  "compression-webpack-plugin": "^9.2.0",
90
91
  "connect-history-api-fallback": "^2.0.0",
91
- "core-js": "^3.47.0",
92
92
  "copy-webpack-plugin": "^10.2.4",
93
93
  "css-loader": "^6.6.0",
94
94
  "css-minimizer-webpack-plugin": "^3.4.1",
@@ -1,15 +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。
9
+ /*
10
+ 备注:后续升级babel版本时,再启用此配置
8
11
  useBuiltIns: 'usage', // 按需引入 polyfill,替代 @babel/polyfill
9
12
  corejs: 3, // 使用 core-js 3.x 版本
10
- targets: {
11
- browsers: ['> 1%', 'last 2 versions', 'not ie <= 8']
12
- }
13
+ */
13
14
  }
14
15
  ],
15
16
  ['@babel/preset-react'],
@@ -15,7 +15,7 @@ module.exports = (akfunConfig) => {
15
15
  const mergedConfig = configManager.mergeConfig(akfunConfig);
16
16
 
17
17
  // 校验当前项目配置
18
- configManager.validateConfig(mergedConfig);
18
+ configManager.validateConfig();
19
19
 
20
20
  return mergedConfig;
21
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 { terser } = require('@rollup/plugin-terser'); // 压缩
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 { externals } = require('rollup-plugin-node-externals');
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'); // 引入当前项目配置文件
@@ -68,7 +68,7 @@ module.exports = function (fileName, akfunConfig) {
68
68
  * excludeList(在akfun.config.js中配置)
69
69
  * 设置打包中应该排除的依赖
70
70
  */
71
- externals({
71
+ nodeExternals({
72
72
  include: build2esm.excludeList || []
73
73
  // exclude: ['./**', '../**'], // 排除所有相对路径模块
74
74
  // deps: true, // 只标记 node_modules 中的依赖
@@ -148,12 +148,12 @@ class ConfigManager {
148
148
  }
149
149
 
150
150
  /**
151
- * 验证配置
151
+ * 验证当前项目的配置(仅验证 userConfig 中的配置)
152
152
  * @returns {Object} 验证后的配置
153
153
  */
154
154
  validateConfig() {
155
- if (!this.mergedConfig) {
156
- this.mergeConfig();
155
+ if (!this.userConfig) {
156
+ return this.userConfig;
157
157
  }
158
158
 
159
159
  try {
@@ -163,7 +163,7 @@ class ConfigManager {
163
163
  // 如果有配置验证器,使用它
164
164
  try {
165
165
  const { validateConfig } = require('../utils/configValidator');
166
- return validateConfig(this.mergedConfig);
166
+ return validateConfig(this.userConfig);
167
167
  } catch (error) {
168
168
  // 如果配置验证器不存在或出错,只进行基础验证
169
169
  if (process.env.AKFUN_DEBUG) {
@@ -171,7 +171,7 @@ class ConfigManager {
171
171
  }
172
172
  }
173
173
 
174
- return this.mergedConfig;
174
+ return this.userConfig;
175
175
  } catch (error) {
176
176
  console.error(chalk.red('\n❌ 配置验证失败:'));
177
177
  console.error(chalk.red(` ${error.message}\n`));
@@ -184,7 +184,7 @@ class ConfigManager {
184
184
  * @private
185
185
  */
186
186
  _validateBasicConfig() {
187
- const config = this.mergedConfig;
187
+ const config = this.userConfig;
188
188
 
189
189
  // 验证必需的配置项
190
190
  if (config.dev && typeof config.dev !== 'object') {
@@ -379,9 +379,9 @@ class ConfigValidator {
379
379
  return;
380
380
  }
381
381
 
382
- if (portNum < 1024 && process.platform !== 'win32') {
382
+ if (portNum < 1024 && process.platform === 'win32') {
383
383
  this.warnings.push(
384
- `${fieldName} (${portNum}) 小于 1024,在非 Windows 系统上可能需要管理员权限`
384
+ `${fieldName} (${portNum}) 小于 1024,在 Windows 系统上可能需要管理员权限。`
385
385
  );
386
386
  }
387
387
  }
@@ -13,6 +13,7 @@ const vueLoaderConfig = require('./vue-loader.conf');
13
13
  const { resolve, resolveToCurrentRoot } = require('../utils/pathUtils');
14
14
  const getProjectDir = require('../utils/getProjectDir');
15
15
  const catchVuePages = require('../utils/catchVuePages'); // 用于获取当前项目中的vue单文件
16
+ const getProjectConfig = require('../config/index'); // 用于获取当前项目配置文件
16
17
  const babelConfig = require('../config/babel.config'); // Babel的配置文件
17
18
  const { buildBanner } = require('../utils/akfunParams');
18
19
  const getJsEntries = require('../utils/jsEntries');
@@ -28,10 +29,11 @@ const BannerPack = new webpack.BannerPlugin({
28
29
  * webpack.base.conf.js
29
30
  * 主要用于设置 rules 和 通用插件
30
31
  * _curEnvConfig: 执行环境中的配置,用于记录 dev、build、build2lib 等对应的配置内容;
31
- * config:完整的配置对象
32
+ * _akfunConfig:完整的配置对象
32
33
  */
33
- module.exports = (_curEnvConfig, config, buildMode = 'build') => {
34
+ module.exports = (_curEnvConfig, _akfunConfig, buildMode = 'build') => {
34
35
  const curEnvConfig = _curEnvConfig || {}; // 用于接收当前运行环境配置变量
36
+ let config = _akfunConfig || getProjectConfig(); // 优先使用外部传进来的项目配置
35
37
  // 获取当前项目配置文件中的webpack配置
36
38
  const curWebpackConfig = config.webpack;
37
39
  // 获取当前项目目录
@@ -3,11 +3,13 @@ const path = require('path');
3
3
  const { merge } = require('webpack-merge');
4
4
  const utils = require('./loaderUtils');
5
5
  const getBaseWebpackConfig = require('./webpack.base.conf'); // 获取webpack基本配置
6
+ const getProjectConfig = require('../config/index'); // 用于获取当前项目配置文件
6
7
  const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
7
8
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
8
9
  // const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
9
10
 
10
- module.exports = (config) => {
11
+ module.exports = (akfunConfig) => {
12
+ let config = akfunConfig || getProjectConfig(); // 优先使用外部传进来的项目配置
11
13
  const curEnvConfig = config.dev || {}; // 当前执行环境配置
12
14
  // 获取webpack基本配置
13
15
  const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config, 'dev');
@@ -6,14 +6,16 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl
6
6
  const deepMergeConfig = require('../utils/deepMergeConfig');
7
7
 
8
8
  const utils = require('./loaderUtils');
9
+ const getProjectConfig = require('../config/index'); // 用于获取当前项目配置文件
9
10
  const getBaseWebpackConfig = require('./webpack.base.conf');
10
11
 
11
12
  /**
12
13
  * 第三方库 webpack 配置,用于构建第三方库(仅构建可用的 umd 模块,其构建产物不会注入到 html 中)
13
- * @param {*} config 当前项目配置
14
+ * @param {*} akfunConfig 当前项目配置
14
15
  * @returns
15
16
  */
16
- module.exports = (config) => {
17
+ module.exports = (akfunConfig) => {
18
+ let config = akfunConfig || getProjectConfig(); // 优先使用外部传进来的项目配置
17
19
  const curEnvConfig = config.build2lib || {}; // 当前执行环境配置
18
20
  // 获取webpack基本配置
19
21
  const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config, 'build2lib');
@@ -11,6 +11,7 @@ const CompressionWebpackPlugin = require('compression-webpack-plugin');
11
11
  const utils = require('./loaderUtils');
12
12
  const { resolve } = require('../utils/pathUtils'); // 统一路径解析
13
13
  const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
14
+ const getProjectConfig = require('../config/index'); // 用于获取当前项目配置文件
14
15
  const getBaseWebpackConfig = require('./webpack.base.conf');
15
16
 
16
17
  /**
@@ -18,7 +19,8 @@ const getBaseWebpackConfig = require('./webpack.base.conf');
18
19
  * @param {*} akfunConfig 当前项目配置
19
20
  * @returns
20
21
  */
21
- module.exports = (config) => {
22
+ module.exports = (akfunConfig) => {
23
+ let config = akfunConfig || getProjectConfig(); // 默认使用执行命令目录下的配置数据
22
24
  const curEnvConfig = config.build || {}; // 当前执行环境配置
23
25
  // 获取webpack基本配置
24
26
  const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config, 'build');