akfun 5.1.11 → 5.1.12
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/package.json
CHANGED
package/src/build2esm.js
CHANGED
|
@@ -12,8 +12,7 @@ async function build2esmFunc(options, curConfig) {
|
|
|
12
12
|
// create a bundle
|
|
13
13
|
const bundle = await rollup.rollup({
|
|
14
14
|
input: options.input,
|
|
15
|
-
|
|
16
|
-
external: curConfig.webpack.externals,
|
|
15
|
+
external: options.externals,
|
|
17
16
|
plugins: options.plugins
|
|
18
17
|
});
|
|
19
18
|
|
|
@@ -38,10 +37,32 @@ module.exports = function (fileName, akfunConfig, _consoleTag) {
|
|
|
38
37
|
const spinner = ora(`${consoleTag}开启esm模块构建能力...`).start();
|
|
39
38
|
const curRollupConfig = rollupConfig(fileName, config); // 默认配置
|
|
40
39
|
const build2esm = config.build2esm; // 用户的项目配置
|
|
40
|
+
const curWebpackConfig = config.webpack;
|
|
41
41
|
const compress = build2esm.compress ?? true; // 是否压缩代码
|
|
42
42
|
if (build2esm && build2esm.input) {
|
|
43
43
|
curRollupConfig.input = build2esm.input;
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
// 处理 externals,用户手动添加要剔除的依赖
|
|
47
|
+
let externals = []; // rollup 的 externals 是数组格式
|
|
48
|
+
|
|
49
|
+
const webpackExternal = curWebpackConfig.external;
|
|
50
|
+
if (webpackExternal && isArray(webpackExternal)) {
|
|
51
|
+
externals = externals.concat(webpackExternal);
|
|
52
|
+
} else if (webpackExternal && isObject(webpackExternal)) {
|
|
53
|
+
externals = externals.concat(Object.keys(webpackExternal));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const build2esmExternal = build2esm.external;
|
|
57
|
+
if (build2esmExternal && isArray(build2esmExternal)) {
|
|
58
|
+
externals = externals.concat(build2esmExternal);
|
|
59
|
+
} else if (build2esmExternal && isObject(build2esmExternal)) {
|
|
60
|
+
externals = externals.concat(Object.keys(build2esmExternal));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 添加到 rollup 配置中
|
|
64
|
+
curRollupConfig.externals = externals;
|
|
65
|
+
|
|
45
66
|
if (build2esm && build2esm.output) {
|
|
46
67
|
curRollupConfig.output = build2esm.output;
|
|
47
68
|
|
|
@@ -33,7 +33,7 @@ module.exports = {
|
|
|
33
33
|
},
|
|
34
34
|
createDeclaration: false, // 打包时是否创建ts声明文件
|
|
35
35
|
ignoreNodeModules: false, // 打包时是否忽略 node_modules
|
|
36
|
-
externals:
|
|
36
|
+
externals: {}, // 从输出的 bundle 中排除依赖
|
|
37
37
|
template: resolve('src/index.html'), // 默认使用的页面模板
|
|
38
38
|
sassResources: []
|
|
39
39
|
},
|
|
@@ -18,7 +18,7 @@ const projectConfig = require('../config/index');
|
|
|
18
18
|
const babelConfig = require('../config/babel.config'); // Babel的配置文件
|
|
19
19
|
const { buildBanner } = require('../utils/akfunParams');
|
|
20
20
|
const getJsEntries = require('../utils/jsEntries');
|
|
21
|
-
const { isArray, isFunction } = require('../utils/typeof');
|
|
21
|
+
const { isArray, isFunction, isObject } = require('../utils/typeof');
|
|
22
22
|
|
|
23
23
|
// 生成构建头部信息
|
|
24
24
|
const BannerPack = new webpack.BannerPlugin({
|
|
@@ -70,6 +70,10 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
70
70
|
output: {
|
|
71
71
|
filename: '[name].js'
|
|
72
72
|
},
|
|
73
|
+
watchOptions: {
|
|
74
|
+
ignored: /node_modules|\.git/, // 忽略 node_modules 和 .git
|
|
75
|
+
aggregateTimeout: 300 // 文件变化后延迟编译的时间(ms)
|
|
76
|
+
},
|
|
73
77
|
/**
|
|
74
78
|
* 当webpack试图去加载模块的时候,它默认是查找以 .js 结尾的文件的
|
|
75
79
|
*/
|
|
@@ -201,6 +205,11 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
201
205
|
]
|
|
202
206
|
};
|
|
203
207
|
|
|
208
|
+
if (curEnvConfig.closeHotReload) {
|
|
209
|
+
// 关闭热更新,则忽略所有文件变化
|
|
210
|
+
webpackConfig.watchOptions.ignored = /.*/; // 忽略所有文件变化
|
|
211
|
+
}
|
|
212
|
+
|
|
204
213
|
let ignoreNodeModules = curWebpackConfig.ignoreNodeModules;
|
|
205
214
|
// 优先使用执行环境中的配置
|
|
206
215
|
if (curEnvConfig.ignoreNodeModules !== undefined) {
|
|
@@ -208,9 +217,15 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
208
217
|
}
|
|
209
218
|
|
|
210
219
|
// allowList 需要开启 ignoreNodeModules 后有效
|
|
211
|
-
|
|
220
|
+
let allowList = curWebpackConfig.allowList || [];
|
|
221
|
+
if (curEnvConfig.allowList) {
|
|
222
|
+
allowList = allowList.concat(curEnvConfig.allowList);
|
|
223
|
+
}
|
|
212
224
|
// 用户手动添加要剔除的依赖
|
|
213
|
-
|
|
225
|
+
let externals = curWebpackConfig.external || {};
|
|
226
|
+
if (curEnvConfig.externals && isObject(curEnvConfig.externals)) {
|
|
227
|
+
externals = Object.assign(externals, curEnvConfig.externals);
|
|
228
|
+
}
|
|
214
229
|
|
|
215
230
|
// 设置要剔除的依赖
|
|
216
231
|
webpackConfig.externals = ignoreNodeModules
|
|
@@ -55,12 +55,24 @@ module.exports = (akfunConfig) => {
|
|
|
55
55
|
emitOnErrors: true
|
|
56
56
|
// minimize: false
|
|
57
57
|
},
|
|
58
|
-
plugins: [
|
|
59
|
-
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
|
|
60
|
-
new webpack.HotModuleReplacementPlugin()
|
|
61
|
-
]
|
|
58
|
+
plugins: []
|
|
62
59
|
});
|
|
63
60
|
|
|
61
|
+
if (!curEnvConfig.closeHotReload) {
|
|
62
|
+
// 开启热更新能力
|
|
63
|
+
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
|
|
64
|
+
webpackDevConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
65
|
+
|
|
66
|
+
// 所有入口文件添加 热更新入口文件
|
|
67
|
+
if (webpackDevConfig.entry) {
|
|
68
|
+
const devClientPath = path.resolve(__dirname, '../dev-client'); // 从 akfun 中获取
|
|
69
|
+
// add hot-reload related code to entry chunks
|
|
70
|
+
Object.keys(webpackDevConfig.entry).forEach((name) => {
|
|
71
|
+
webpackDevConfig.entry[name] = [devClientPath].concat(webpackDevConfig.entry[name]);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
// 支持 cssExtract 配置
|
|
65
77
|
if (curEnvConfig.cssExtract || curEnvConfig.cssExtract === undefined) {
|
|
66
78
|
webpackDevConfig.plugins.push(
|
|
@@ -81,15 +93,6 @@ module.exports = (akfunConfig) => {
|
|
|
81
93
|
});
|
|
82
94
|
}
|
|
83
95
|
|
|
84
|
-
if (!curEnvConfig.closeHotReload && webpackDevConfig.entry) {
|
|
85
|
-
// 开启热更新能力
|
|
86
|
-
const devClientPath = path.resolve(__dirname, '../dev-client'); // 从akfun中获取
|
|
87
|
-
// add hot-reload related code to entry chunks
|
|
88
|
-
Object.keys(webpackDevConfig.entry).forEach((name) => {
|
|
89
|
-
webpackDevConfig.entry[name] = [devClientPath].concat(webpackDevConfig.entry[name]);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
96
|
// 判断当前环境是否有自定义plugins
|
|
94
97
|
if (curEnvConfig.plugins && Array.isArray(curEnvConfig.plugins)) {
|
|
95
98
|
// 添加自定义webpack插件
|