akfun 5.1.10 → 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
|
|
package/src/dev-server.js
CHANGED
|
@@ -92,15 +92,17 @@ module.exports = function (akfunConfig, _consoleTag) {
|
|
|
92
92
|
// serve webpack bundle output
|
|
93
93
|
app.use(devMiddleware);
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
if (!curEnvConfig.closeHotReload) {
|
|
96
|
+
// 启动 webpack-hot-middleware,也就是我们常说的 Hot-reload
|
|
97
|
+
const hotMiddleware = require('webpack-hot-middleware')(compiler, {
|
|
98
|
+
log: false,
|
|
99
|
+
heartbeat: 2000
|
|
100
|
+
});
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
// enable hot-reload and state-preserving
|
|
103
|
+
// compilation error display
|
|
104
|
+
app.use(hotMiddleware);
|
|
105
|
+
}
|
|
104
106
|
|
|
105
107
|
const afterCreateServerAction = (isHttps, port) => {
|
|
106
108
|
spinner.succeed(`${consoleTag}调试模式已开启!`);
|
|
@@ -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({
|
|
@@ -29,7 +29,7 @@ const BannerPack = new webpack.BannerPlugin({
|
|
|
29
29
|
/**
|
|
30
30
|
* webpack.base.conf.js
|
|
31
31
|
* 主要用于设置 rules 和 通用插件
|
|
32
|
-
* _curEnvConfig:
|
|
32
|
+
* _curEnvConfig: 执行环境中的配置,用于记录 dev、build、build2lib 等对应的配置内容;
|
|
33
33
|
* _akfunConfig:完整的配置对象
|
|
34
34
|
*/
|
|
35
35
|
module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
@@ -70,19 +70,15 @@ 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
|
*/
|
|
76
80
|
resolve: curWebpackConfig.resolve,
|
|
77
|
-
externals:
|
|
78
|
-
? [
|
|
79
|
-
nodeExternals({
|
|
80
|
-
importType: 'commonjs',
|
|
81
|
-
additionalModuleDirs: curWebpackConfig.additionalModuleDirs || [],
|
|
82
|
-
allowlist: curWebpackConfig.allowList ? curWebpackConfig.allowList : []
|
|
83
|
-
})
|
|
84
|
-
].concat(curWebpackConfig.externals)
|
|
85
|
-
: curWebpackConfig.externals,
|
|
81
|
+
externals: {},
|
|
86
82
|
module: {
|
|
87
83
|
rules: [
|
|
88
84
|
{
|
|
@@ -208,28 +204,48 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
208
204
|
new ProgressBarPlugin()
|
|
209
205
|
]
|
|
210
206
|
};
|
|
207
|
+
|
|
208
|
+
if (curEnvConfig.closeHotReload) {
|
|
209
|
+
// 关闭热更新,则忽略所有文件变化
|
|
210
|
+
webpackConfig.watchOptions.ignored = /.*/; // 忽略所有文件变化
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let ignoreNodeModules = curWebpackConfig.ignoreNodeModules;
|
|
211
214
|
// 优先使用执行环境中的配置
|
|
212
215
|
if (curEnvConfig.ignoreNodeModules !== undefined) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
216
|
+
ignoreNodeModules = curEnvConfig.ignoreNodeModules;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// allowList 需要开启 ignoreNodeModules 后有效
|
|
220
|
+
let allowList = curWebpackConfig.allowList || [];
|
|
221
|
+
if (curEnvConfig.allowList) {
|
|
222
|
+
allowList = allowList.concat(curEnvConfig.allowList);
|
|
223
|
+
}
|
|
224
|
+
// 用户手动添加要剔除的依赖
|
|
225
|
+
let externals = curWebpackConfig.external || {};
|
|
226
|
+
if (curEnvConfig.externals && isObject(curEnvConfig.externals)) {
|
|
227
|
+
externals = Object.assign(externals, curEnvConfig.externals);
|
|
225
228
|
}
|
|
229
|
+
|
|
230
|
+
// 设置要剔除的依赖
|
|
231
|
+
webpackConfig.externals = ignoreNodeModules
|
|
232
|
+
? [
|
|
233
|
+
nodeExternals({
|
|
234
|
+
importType: 'commonjs',
|
|
235
|
+
additionalModuleDirs:
|
|
236
|
+
curEnvConfig.additionalModuleDirs || curWebpackConfig.additionalModuleDirs || [],
|
|
237
|
+
allowlist: allowList || []
|
|
238
|
+
})
|
|
239
|
+
].concat(externals)
|
|
240
|
+
: externals;
|
|
241
|
+
|
|
226
242
|
// 集成构建入口相关的配置(优先级更高)
|
|
227
243
|
if (curEnvConfig.entry) {
|
|
228
244
|
webpackConfig.entry = curEnvConfig.entry; // 会覆盖config.webpack.entry的配置
|
|
229
245
|
}
|
|
230
246
|
// 多页面多模板支持能力
|
|
231
247
|
let entryConfig = webpackConfig.entry || {}; // 获取构建入口配置
|
|
232
|
-
const entryFiles =
|
|
248
|
+
const entryFiles = Object.keys(entryConfig);
|
|
233
249
|
|
|
234
250
|
if (
|
|
235
251
|
!webpackConfig.entry ||
|
|
@@ -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
|
-
// 开启热更新能力
|
|
85
|
-
const devClientPath = path.resolve(__dirname, '../dev-client'); // 从akfun中获取
|
|
86
|
-
// add hot-reload related code to entry chunks
|
|
87
|
-
if (!curEnvConfig.closeHotReload && webpackDevConfig.entry) {
|
|
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插件
|