akfun 5.2.0 → 5.2.2
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 +5 -5
- package/src/build2node.js +4 -3
- package/src/rollup/build.js +2 -2
- package/src/rollup/rollup.node.config.js +3 -3
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const getProjectConfig = require('./config/index'); // 用于获取当前项目配置文件
|
|
2
|
-
const rollupConfig = require('./config/rollup.config'); // rollup的配置文件
|
|
3
2
|
const { curConsoleTag } = require('./utils/akfunParams');
|
|
4
3
|
const rollupBuild = require('./rollup/build');
|
|
4
|
+
const rollupConfig = require('./rollup/rollup.config'); // rollup的配置文件
|
|
5
5
|
/**
|
|
6
6
|
* 用于构建 esm 模块
|
|
7
7
|
* @param {*} akfunConfig akfun 配置文件
|
|
@@ -26,12 +26,12 @@ module.exports = function (akfunConfig, _consoleTag) {
|
|
|
26
26
|
const consoleTag = _consoleTag || curConsoleTag;
|
|
27
27
|
// 获取项目配置文件
|
|
28
28
|
let config = getProjectConfig(akfunConfig);
|
|
29
|
-
|
|
30
|
-
const curRollupConfig = rollupConfig(fileName, config); // 默认配置
|
|
31
29
|
const build2esm = config.build2esm; // 用户的项目配置
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const curRollupConfig = rollupConfig(config, build2esm); // 默认配置
|
|
32
|
+
|
|
33
|
+
if (build2esm && !build2esm.format) {
|
|
34
|
+
build2esm.format = 'esm'; // 默认构建格式为 esm
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
rollupBuild(config, build2esm, curRollupConfig, consoleTag);
|
package/src/build2node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const getProjectConfig = require('./config/index'); // 用于获取当前项目配置文件
|
|
2
|
-
const rollupConfig = require('./config/rollup.node.config'); // rollup的配置文件
|
|
3
2
|
const { curConsoleTag } = require('./utils/akfunParams');
|
|
4
3
|
const rollupBuild = require('./rollup/build');
|
|
4
|
+
const rollupConfig = require('./rollup/rollup.node.config'); // rollup的配置文件
|
|
5
5
|
/**
|
|
6
6
|
* 用于构建 esm 模块
|
|
7
7
|
* @param {*} akfunConfig akfun 配置文件
|
|
@@ -12,6 +12,7 @@ const rollupBuild = require('./rollup/build');
|
|
|
12
12
|
* - input: 构建入口文件
|
|
13
13
|
* - fileName: 构建输出文件名
|
|
14
14
|
* - outDir: 构建输出目录
|
|
15
|
+
* - preserveModules: 是否保留原始模块结构,不合并文件
|
|
15
16
|
* - excludeList: 构建排除列表
|
|
16
17
|
* - declaration: 是否生成声明文件
|
|
17
18
|
* - declarationDir: 声明文件输出目录
|
|
@@ -22,10 +23,10 @@ module.exports = function (akfunConfig, _consoleTag) {
|
|
|
22
23
|
const consoleTag = _consoleTag || curConsoleTag;
|
|
23
24
|
// 获取项目配置文件
|
|
24
25
|
let config = getProjectConfig(akfunConfig);
|
|
25
|
-
|
|
26
|
-
const curRollupConfig = rollupConfig(fileName, config); // 默认配置
|
|
27
26
|
const build2node = config.build2node; // 用户的项目配置
|
|
28
27
|
|
|
28
|
+
const curRollupConfig = rollupConfig(config, build2node); // 默认配置
|
|
29
|
+
|
|
29
30
|
build2node.format = 'cjs'; // 构建格式固定为 cjs,无需用户配置
|
|
30
31
|
|
|
31
32
|
rollupBuild(config, build2node, curRollupConfig, consoleTag);
|
package/src/rollup/build.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const ora = require('ora');
|
|
2
2
|
const rollup = require('rollup');
|
|
3
3
|
const terser = require('@rollup/plugin-terser'); // 压缩
|
|
4
|
-
const { isArray, isObject } = require('
|
|
5
|
-
const { curConsoleTag } = require('
|
|
4
|
+
const { isArray, isObject } = require('../utils/typeof');
|
|
5
|
+
const { curConsoleTag } = require('../utils/akfunParams');
|
|
6
6
|
|
|
7
7
|
async function rollupBuildFunc(envConfig, curConfig) {
|
|
8
8
|
// create a bundle
|
|
@@ -74,9 +74,9 @@ module.exports = function (curConfig, curEnvConfig) {
|
|
|
74
74
|
json()
|
|
75
75
|
],
|
|
76
76
|
output: {
|
|
77
|
-
dir: resolve('dist'),
|
|
78
|
-
format:
|
|
79
|
-
preserveModules: true, // 关键:保留原始模块结构,不合并文件
|
|
77
|
+
dir: curEnvConfig.outDir || resolve('dist'),
|
|
78
|
+
format: buildFormat, // which can be one of "amd", "cjs", "system", "es", "iife" or "umd".
|
|
79
|
+
preserveModules: curEnvConfig.preserveModules !== undefined ? curEnvConfig.preserveModules : true, // 关键:保留原始模块结构,不合并文件
|
|
80
80
|
preserveModulesRoot: 'src', // 指定模块根目录
|
|
81
81
|
exports: 'auto', // 自动处理导出(适配 ES 模块的默认导出/命名导出)
|
|
82
82
|
generatedCode: 'es2015', // 使用现代 JavaScript 语法生成代码
|