akfun 5.1.13 → 5.1.16

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
@@ -12,11 +12,18 @@ const getCurWebpackConfig = require('../src/utils/getCurWebpackConfig.js'); //
12
12
  const aliBOS = require('../src/oss/aliBos.js');
13
13
  const baiduBOS = require('../src/oss/baiduBos.js');
14
14
 
15
+ // 新增:配置管理和环境管理
16
+ const configManager = require('../src/config/ConfigManager');
17
+ const { validateConfig } = require('../src/utils/configValidator');
18
+
15
19
  module.exports = {
20
+ // 核心功能
16
21
  dev: devAction,
17
22
  build: buildAction,
18
23
  build2esm,
19
24
  inspect,
25
+
26
+ // 工具方法
20
27
  gitClone,
21
28
  createFile,
22
29
  resolve,
@@ -24,6 +31,12 @@ module.exports = {
24
31
  deepMergeConfig,
25
32
  getCurWebpackConfig,
26
33
  curWebpackBaseConfPath: getCurWebpackConfig('base'),
34
+
35
+ // OSS 上传
27
36
  aliBOS,
28
- baiduBOS
37
+ baiduBOS,
38
+
39
+ // 新增:配置管理
40
+ configManager,
41
+ validateConfig
29
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akfun",
3
- "version": "5.1.13",
3
+ "version": "5.1.16",
4
4
  "description": "前端脚手架:支持Vue技术栈和react技术栈",
5
5
  "keywords": [
6
6
  "前端工程",
@@ -62,21 +62,21 @@
62
62
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
63
63
  "@babel/plugin-syntax-import-meta": "^7.10.4",
64
64
  "@babel/plugin-transform-runtime": "^7.27.1",
65
- "@babel/polyfill": "^7.10.1",
66
65
  "@babel/runtime": "^7.27.1",
67
66
  "@babel/preset-env": "^7.16.11",
68
67
  "@babel/preset-react": "^7.16.7",
69
68
  "@babel/preset-typescript": "^7.16.7",
70
69
  "@babel/register": "^7.17.0",
71
70
  "@mapbox/stylelint-processor-arbitrary-tags": "^0.4.0",
72
- "@rollup/plugin-alias": "^3.1.9",
73
- "@rollup/plugin-babel": "^5.3.0",
74
- "@rollup/plugin-commonjs": "^21.0.1",
75
- "@rollup/plugin-image": "^2.1.1",
71
+ "@rollup/plugin-alias": "^6.0.0",
72
+ "@rollup/plugin-babel": "^6.1.0",
73
+ "@rollup/plugin-commonjs": "^29.0.0",
74
+ "@rollup/plugin-image": "^3.0.3",
76
75
  "@svgr/rollup": "^8.1.0",
77
- "@rollup/plugin-json": "^4.1.0",
78
- "@rollup/plugin-node-resolve": "^13.1.3",
79
- "@rollup/plugin-typescript": "^8.3.1",
76
+ "@rollup/plugin-json": "^6.1.0",
77
+ "@rollup/plugin-node-resolve": "^16.0.3",
78
+ "@rollup/plugin-typescript": "^12.3.0",
79
+ "@rollup/plugin-terser": "^0.4.4",
80
80
  "@svgr/webpack": "^6.2.1",
81
81
  "@typescript-eslint/eslint-plugin": "^5.10.2",
82
82
  "@typescript-eslint/parser": "^5.10.2",
@@ -88,6 +88,7 @@
88
88
  "chalk": "^4.0.0",
89
89
  "compression-webpack-plugin": "^9.2.0",
90
90
  "connect-history-api-fallback": "^2.0.0",
91
+ "core-js": "^3.47.0",
91
92
  "copy-webpack-plugin": "^10.2.4",
92
93
  "css-loader": "^6.6.0",
93
94
  "css-minimizer-webpack-plugin": "^3.4.1",
@@ -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": "^2.67.0",
133
- "rollup-plugin-node-externals": "^4.0.0",
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.49.7",
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": ">= 10.13.0",
179
- "npm": ">= 6.4.1"
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 projectConfig = require('./config/index'); // 引入当前项目配置文件
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
- let config = projectConfig; // 默认使用执行命令目录下的配置数据
16
- if (akfunConfig) {
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-plugin-terser'); // 压缩
4
- const projectConfig = require('./config/index'); // 引入当前项目配置文件
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
- options.output.map((outputItem) => {
21
- bundle.write(outputItem);
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
- let config = projectConfig; // 默认使用执行命令目录下的配置数据
33
- if (akfunConfig) {
34
- // 参数中的config配置优先级最高
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.externals = externals;
61
+ // 添加到 rollup 配置中(rollup 使用 external 而不是 externals)
62
+ curRollupConfig.external = externals;
65
63
 
66
64
  if (build2esm && build2esm.output) {
67
65
  curRollupConfig.output = build2esm.output;
@@ -5,6 +5,8 @@ module.exports = {
5
5
  {
6
6
  loose: true,
7
7
  modules: false, // 是否启用将ES6模块语法转换为其他模块类型的功能,当前设置为false,以便webpack进行tree shaking。
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
  }
@@ -1,15 +1,21 @@
1
- // 统一路径解析:
2
- const { resolve } = require('../utils/pathUtils');
3
- const defaultAKFunConfig = require('./default.config');
4
- const getConfigObj = require('../utils/getConfigObj');
5
- const deepMergeConfig = require('../utils/deepMergeConfig');
6
-
7
- /** akfun脚手架赋予当前项目的默认配置
8
- * 备注:项目根目录的akfun.config.js的配置内容优先级高于defultAKFunConfig
1
+ /**
2
+ * 配置入口文件
3
+ * 统一加载和管理 AKFun 配置
9
4
  */
5
+ // 使用新的配置管理器
6
+ const configManager = require('../manage/ConfigManager');
7
+
8
+ // 导出合并后的配置(向后兼容)
9
+ module.exports = (akfunConfig) => {
10
+ if (!akfunConfig) {
11
+ // 自动加载用户配置文件
12
+ configManager.autoLoadConfig();
13
+ }
14
+ // 合并配置
15
+ const mergedConfig = configManager.mergeConfig(akfunConfig);
10
16
 
11
- // 从项目根目录获取当前项目的配置文件
12
- const curProjectConfig = getConfigObj(resolve('akfun.config.js'));
17
+ // 校验当前项目配置
18
+ configManager.validateConfig(mergedConfig);
13
19
 
14
- // 备注:数组类型则直接覆盖
15
- module.exports = deepMergeConfig(defaultAKFunConfig, curProjectConfig);
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 { 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');
@@ -57,9 +57,12 @@ module.exports = function (fileName, akfunConfig) {
57
57
  input: rollupInput,
58
58
  plugins: [
59
59
  alias({
60
- resolve: curConfig.webpack.resolve.extensions,
61
- extensions: curConfig.webpack.resolve.extensions,
62
- entries: curConfig.webpack.resolve.alias
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中配置)
@@ -67,7 +70,17 @@ module.exports = function (fileName, akfunConfig) {
67
70
  */
68
71
  externals({
69
72
  include: build2esm.excludeList || []
73
+ // exclude: ['./**', '../**'], // 排除所有相对路径模块
74
+ // deps: true, // 只标记 node_modules 中的依赖
75
+ // devDeps: false, // 不标记 devDependencies
76
+ // peerDeps: true, // 标记 peerDependencies
70
77
  }),
78
+ /**
79
+ * nodeResolve 插件用于解析模块路径
80
+ * extensions: 默认识别的文件后缀列表
81
+ * 默认值(来自 webpack.resolve.extensions): ['.js', '.jsx', '.ts', '.tsx', '.vue', '.json']
82
+ * 如果不配置此插件,Rollup 默认只识别 .js 和 .mjs 文件
83
+ */
71
84
  nodeResolve({
72
85
  extensions: curConfig.webpack.resolve.extensions
73
86
  }),
@@ -82,7 +95,11 @@ module.exports = function (fileName, akfunConfig) {
82
95
  // jsx( {factory: 'React.createElement'} ),
83
96
  buildType === 'ts' ? undefined : jsx({ factory: 'React.createElement' }),
84
97
  vue(),
85
- commonjs(),
98
+ commonjs({
99
+ transformMixedEsModules: true, // 转换混合的 ES 模块和 CommonJS 模块
100
+ strictRequires: true, // 严格模式处理 require,确保所有 require 都被正确处理
101
+ ignoreDynamicRequires: true // 忽略动态 require
102
+ }),
86
103
  postcss({
87
104
  extensions: ['.css', '.scss', '.sass', '.styl', '.stylus', '.less'],
88
105
  // Or with custom file name, it will generate file relative to bundle.js in v3
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
- let config = projectConfig; // 默认使用执行命令目录下的配置数据
23
- if (akfunConfig) {
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": "^3.1.9",
65
- "@rollup/plugin-babel": "^5.3.0",
66
- "@rollup/plugin-commonjs": "^21.0.1",
67
- "@rollup/plugin-image": "^2.1.1",
68
- "@rollup/plugin-json": "^4.1.0",
69
- "@rollup/plugin-node-resolve": "^13.1.3",
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.49.7",
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": "^2.67.0",
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.export = {
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
  }