akfun 5.2.1 → 5.2.3
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 +16 -1
- package/package.json +1 -1
- package/src/build2esm.js +1 -1
- package/src/build2node.js +2 -1
- package/src/rollup/build.js +11 -12
- package/src/rollup/rollup.config.js +1 -1
- package/src/rollup/rollup.node.config.js +6 -5
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ AKFun 是一个基于 Webpack 与 Rollup 的多场景前端打包工具,支持
|
|
|
22
22
|
|
|
23
23
|
- **零配置**: 内置默认配置,开箱即用
|
|
24
24
|
- **多技术栈**: 支持 Vue、React、React+TS 的调试与构建
|
|
25
|
-
- **多构建场景**: 本地开发(含热更新/代理)、生产构建、库构建(UMD/ESM
|
|
25
|
+
- **多构建场景**: 本地开发(含热更新/代理)、生产构建、库构建(UMD/ESM)、Node 模块构建
|
|
26
26
|
- **灵活可配**: 支持入口、别名、代理、SASS 注入、ESLint/StyleLint、Babel/Loader/Plugin 扩展等配置
|
|
27
27
|
- **样式与规范**: 集成 Autoprefixer、Sass、PostCSS、ESLint、StyleLint
|
|
28
28
|
- **参数替换**: 支持基于 [params-replace-loader](https://www.npmjs.com/package/params-replace-loader) 的环境变量批量替换
|
|
@@ -114,6 +114,7 @@ npm i akfun --save-dev
|
|
|
114
114
|
| `akfun build` | 生产环境构建(压缩优化、可选分析) |
|
|
115
115
|
| `akfun build2lib` | 构建 UMD 格式的库产物 |
|
|
116
116
|
| `akfun build2esm` | 构建 ESM 格式的库产物 |
|
|
117
|
+
| `akfun build2node` | 构建 Node 模块 |
|
|
117
118
|
|
|
118
119
|
---
|
|
119
120
|
|
|
@@ -379,6 +380,20 @@ module.exports = {
|
|
|
379
380
|
}
|
|
380
381
|
```
|
|
381
382
|
|
|
383
|
+
#### 构建 Node 模块
|
|
384
|
+
|
|
385
|
+
构建 Node 模块,通常用于构建 node cli 工具:
|
|
386
|
+
|
|
387
|
+
```javascript
|
|
388
|
+
module.exports = {
|
|
389
|
+
build2node: {
|
|
390
|
+
input: resolve('src/main.js'), // 入口文件
|
|
391
|
+
fileName: 'index', // 输出的文件名称
|
|
392
|
+
outDir: 'src' // 输出目录
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
382
397
|
---
|
|
383
398
|
|
|
384
399
|
### 高级配置
|
package/package.json
CHANGED
package/src/build2esm.js
CHANGED
package/src/build2node.js
CHANGED
|
@@ -6,12 +6,13 @@ const rollupConfig = require('./rollup/rollup.node.config'); // rollup的配置
|
|
|
6
6
|
* 用于构建 esm 模块
|
|
7
7
|
* @param {*} akfunConfig akfun 配置文件
|
|
8
8
|
* @param {*} _consoleTag 控制台输出标签
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* 支持的配置项目(akfunConfig.build2node)
|
|
11
11
|
* - type: 项目构建类型(ts、js)
|
|
12
12
|
* - input: 构建入口文件
|
|
13
13
|
* - fileName: 构建输出文件名
|
|
14
14
|
* - outDir: 构建输出目录
|
|
15
|
+
* - preserveModules: 是否保留原始模块结构,不合并文件
|
|
15
16
|
* - excludeList: 构建排除列表
|
|
16
17
|
* - declaration: 是否生成声明文件
|
|
17
18
|
* - declarationDir: 声明文件输出目录
|
package/src/rollup/build.js
CHANGED
|
@@ -63,18 +63,17 @@ module.exports = function (config, envConfig, _rollupConfig, _consoleTag) {
|
|
|
63
63
|
|
|
64
64
|
if (envConfig && envConfig.output) {
|
|
65
65
|
curRollupConfig.output = envConfig.output;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
66
|
+
}
|
|
67
|
+
if (compress && isArray(curRollupConfig.output)) {
|
|
68
|
+
curRollupConfig.output.map((outputItem) => {
|
|
69
|
+
if (!outputItem.plugins) {
|
|
70
|
+
outputItem.plugins = [terser()];
|
|
71
|
+
} else {
|
|
72
|
+
outputItem.plugins.push(terser());
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
} else if (compress && isObject(curRollupConfig.output) && !curRollupConfig.output.plugins) {
|
|
76
|
+
curRollupConfig.output.plugins = [terser()];
|
|
78
77
|
}
|
|
79
78
|
const spinner = ora(`${consoleTag}开启${buildFormat}模块构建模式...`).start();
|
|
80
79
|
rollupBuildFunc(curRollupConfig, config).then(() => {
|
|
@@ -14,7 +14,7 @@ const { resolve } = require('../utils/pathUtils'); // 统一路径解析
|
|
|
14
14
|
* 备注:node 模块构建不需要使用 babel,也不需要处理css、图片、svg 等文件。
|
|
15
15
|
* @param {*} curConfig 当前项目配置
|
|
16
16
|
* @param {*} curEnvConfig 当前环境配置
|
|
17
|
-
*
|
|
17
|
+
*
|
|
18
18
|
* 支持的配置项目(curEnvConfig)
|
|
19
19
|
* - type: 项目构建类型(ts、js)
|
|
20
20
|
* - format: 构建格式(esm、cjs)
|
|
@@ -74,14 +74,15 @@ module.exports = function (curConfig, curEnvConfig) {
|
|
|
74
74
|
json()
|
|
75
75
|
],
|
|
76
76
|
output: {
|
|
77
|
-
dir: resolve('dist'),
|
|
77
|
+
dir: curEnvConfig.outDir || resolve('dist'),
|
|
78
78
|
format: buildFormat, // which can be one of "amd", "cjs", "system", "es", "iife" or "umd".
|
|
79
|
-
preserveModules:
|
|
79
|
+
preserveModules:
|
|
80
|
+
curEnvConfig.preserveModules !== undefined ? curEnvConfig.preserveModules : true, // 关键:保留原始模块结构,不合并文件
|
|
80
81
|
preserveModulesRoot: 'src', // 指定模块根目录
|
|
81
82
|
exports: 'auto', // 自动处理导出(适配 ES 模块的默认导出/命名导出)
|
|
82
83
|
generatedCode: 'es2015', // 使用现代 JavaScript 语法生成代码
|
|
83
|
-
entryFileNames: '[name].js'
|
|
84
|
+
entryFileNames: '[name].js'
|
|
84
85
|
// interop: 'auto' // 自动处理 CJS/ES 模块互操作(如 __esModule 标记)
|
|
85
|
-
}
|
|
86
|
+
}
|
|
86
87
|
};
|
|
87
88
|
};
|