akfun 5.1.15 → 5.1.17
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 +342 -215
- package/module/main.js +1 -1
- package/package.json +15 -15
- package/src/build.js +3 -8
- package/src/build2esm.js +13 -15
- package/src/config/babel.config.js +6 -3
- package/src/config/index.js +12 -10
- package/src/config/rollup.config.js +15 -6
- package/src/dev-server.js +3 -9
- package/src/initData/akfun-package.json +14 -10
- package/src/initData/config/babel.config.js +3 -1
- package/src/manage/ConfigManager.js +16 -18
- package/src/utils/configValidator.js +10 -15
- package/src/webpack/loaderUtils.js +30 -20
- package/src/webpack/vue-loader.conf.js +2 -12
- package/src/webpack/webpack.base.conf.js +55 -15
- package/src/webpack/webpack.dev.conf.js +9 -14
- package/src/webpack/webpack.library.conf.js +7 -12
- package/src/webpack/webpack.prod.conf.js +9 -14
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // 替换extract-text-webpack-plugin
|
|
3
3
|
// const ExtractTextPlugin = require('extract-text-webpack-plugin'); // 不支持webpack4.0
|
|
4
|
-
// 引入当前项目配置文件
|
|
5
|
-
const config = require('../config/index');
|
|
6
4
|
const postCssConfig = require('../config/postcss.config'); // PostCss的配置文件
|
|
7
5
|
|
|
8
6
|
exports.assetsPath = function (_path) {
|
|
9
|
-
const assetsSubDirectory =
|
|
10
|
-
process.NODE_ENV === 'production'
|
|
11
|
-
? config.build.assetsSubDirectory
|
|
12
|
-
: config.dev.assetsSubDirectory;
|
|
7
|
+
const assetsSubDirectory = '';
|
|
13
8
|
return path.posix.join(assetsSubDirectory, _path);
|
|
14
9
|
};
|
|
15
10
|
|
|
@@ -23,13 +18,29 @@ function getAssetsPath(url) {
|
|
|
23
18
|
return newUrl;
|
|
24
19
|
}
|
|
25
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 用于生成css-loader配置
|
|
23
|
+
* @param {*} options
|
|
24
|
+
* @param {Object} options.envConfig 当前环境配置
|
|
25
|
+
* @param {Object} options.webpackConfig 当前webpack配置
|
|
26
|
+
* @returns {Object} css-loader配置
|
|
27
|
+
* webpackConfig.cssLoaderUrl, // 用于自定义css-loader配置项[url]
|
|
28
|
+
* webpackConfig.cssLoaderUrlDir, // 用于设置css-loader配置项[url]的生效目录
|
|
29
|
+
* webpackConfig.cssLoaderOption, // 用于自定义css-loader配置项(优先级最高)
|
|
30
|
+
* webpackConfig.sassOptions, // 用于设置sass-loader配置项
|
|
31
|
+
* webpackConfig.productionSourceMap, // 生产环境sourceMap是true
|
|
32
|
+
* webpackConfig.NODE_ENV // 生产环境下:将相关的样式内容提取出来合并到一个文件中
|
|
33
|
+
* @returns {Object} css-loader 配置
|
|
34
|
+
*/
|
|
26
35
|
exports.cssLoaders = function (options) {
|
|
27
36
|
options = options || {};
|
|
37
|
+
const curEnvConfig = options.envConfig || {};
|
|
38
|
+
const curWebpackConfig = options.webpackConfig || {};
|
|
28
39
|
|
|
29
40
|
const VueCssLoader = {
|
|
30
41
|
loader: 'vue-style-loader',
|
|
31
42
|
options: {
|
|
32
|
-
sourceMap:
|
|
43
|
+
sourceMap: curEnvConfig.productionSourceMap
|
|
33
44
|
}
|
|
34
45
|
};
|
|
35
46
|
|
|
@@ -39,22 +50,22 @@ exports.cssLoaders = function (options) {
|
|
|
39
50
|
// url: false, // enables/disables url()/image-set() functions handling
|
|
40
51
|
url: {
|
|
41
52
|
filter: (url, resourcePath) => {
|
|
42
|
-
if (
|
|
53
|
+
if (curWebpackConfig.cssLoaderUrlDir && resourcePath.includes(curWebpackConfig.cssLoaderUrlDir)) {
|
|
43
54
|
// 指定处理某类路径下的中相关 css 文件中的 url
|
|
44
55
|
return true;
|
|
45
56
|
}
|
|
46
57
|
if (url.startsWith('data:')) {
|
|
47
58
|
// 不处理 css 中的 bas64 url
|
|
48
59
|
return false;
|
|
49
|
-
} else if (
|
|
60
|
+
} else if (curWebpackConfig.cssLoaderUrl !== undefined) {
|
|
50
61
|
// cssLoaderUrl 为false 则不处理 css 中的 url
|
|
51
|
-
return
|
|
62
|
+
return curWebpackConfig.cssLoaderUrl;
|
|
52
63
|
}
|
|
53
64
|
return true;
|
|
54
65
|
}
|
|
55
66
|
},
|
|
56
|
-
sourceMap:
|
|
57
|
-
...(
|
|
67
|
+
sourceMap: curEnvConfig.productionSourceMap,
|
|
68
|
+
...(curWebpackConfig.cssLoaderOption || {})
|
|
58
69
|
}
|
|
59
70
|
};
|
|
60
71
|
|
|
@@ -62,7 +73,7 @@ exports.cssLoaders = function (options) {
|
|
|
62
73
|
loader: 'postcss-loader',
|
|
63
74
|
options: {
|
|
64
75
|
...postCssConfig,
|
|
65
|
-
...(
|
|
76
|
+
...(curWebpackConfig.postCssLoaderOption || {})
|
|
66
77
|
}
|
|
67
78
|
};
|
|
68
79
|
|
|
@@ -70,8 +81,7 @@ exports.cssLoaders = function (options) {
|
|
|
70
81
|
function generateLoaders(loader, loaderOptions) {
|
|
71
82
|
let loaders = [];
|
|
72
83
|
// 生产环境使用MiniCssExtractPlugin提取css内容,用于提取css内容到一个独立的文件中
|
|
73
|
-
if (
|
|
74
|
-
const curEnvConfig = options.envConfig || {};
|
|
84
|
+
if (curEnvConfig.NODE_ENV === 'production') {
|
|
75
85
|
const cssExtract = curEnvConfig.cssExtract || curEnvConfig.cssExtract === undefined;
|
|
76
86
|
// MiniCssExtractPlugin.loader 需要配合 MiniCssExtractPlugin 使用
|
|
77
87
|
loaders = [
|
|
@@ -94,20 +104,20 @@ exports.cssLoaders = function (options) {
|
|
|
94
104
|
if (loader) {
|
|
95
105
|
loaders.push({
|
|
96
106
|
loader: `${loader}-loader`,
|
|
97
|
-
options: { ...loaderOptions, sourceMap:
|
|
107
|
+
options: { ...loaderOptions, sourceMap: curEnvConfig.productionSourceMap }
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
110
|
|
|
101
111
|
// 如果是sass、scss文件,则增加sass-resources-loader
|
|
102
112
|
if (
|
|
103
113
|
(loader === 'sass' || loader === 'scss') &&
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
curWebpackConfig.sassResources &&
|
|
115
|
+
curWebpackConfig.sassResources.length > 0
|
|
106
116
|
) {
|
|
107
117
|
loaders.push({
|
|
108
118
|
loader: 'sass-resources-loader',
|
|
109
119
|
options: {
|
|
110
|
-
resources:
|
|
120
|
+
resources: curWebpackConfig.sassResources || []
|
|
111
121
|
}
|
|
112
122
|
});
|
|
113
123
|
}
|
|
@@ -115,7 +125,7 @@ exports.cssLoaders = function (options) {
|
|
|
115
125
|
return loaders;
|
|
116
126
|
}
|
|
117
127
|
|
|
118
|
-
const sassOptions =
|
|
128
|
+
const sassOptions = curWebpackConfig.sassOptions || {};
|
|
119
129
|
|
|
120
130
|
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
|
|
121
131
|
return {
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
const utils = require('./loaderUtils');
|
|
2
|
-
// 引入当前项目配置文件
|
|
3
|
-
const config = require('../config/index');
|
|
4
|
-
const isProduction = process.NODE_ENV === 'production';
|
|
5
2
|
|
|
6
|
-
module.exports = (curEnvConfig) => {
|
|
3
|
+
module.exports = (curEnvConfig, curWebpackConfig) => {
|
|
7
4
|
return {
|
|
8
5
|
loaders: utils.cssLoaders({
|
|
9
6
|
envConfig: curEnvConfig, // 当前环境变量
|
|
10
|
-
|
|
11
|
-
cssLoaderUrlDir: config.webpack.cssLoaderUrlDir, // 用于设置css-loader配置项[url]的生效目录
|
|
12
|
-
cssLoaderOption: config.webpack.cssLoaderOption, // 用于自定义css-loader配置项(优先级最高)
|
|
13
|
-
sassOptions: config.webpack.sassOptions, // 用于设置sass-loader配置项
|
|
14
|
-
sourceMap: isProduction // 生产环境sourceMap是true
|
|
15
|
-
? config.build.productionSourceMap
|
|
16
|
-
: config.dev.cssSourceMap,
|
|
17
|
-
environment: isProduction ? 'prod' : 'dev' // 生产环境下:将相关的样式内容提取出来合并到一个文件中
|
|
7
|
+
webpackConfig: curWebpackConfig, // 当前webpack配置
|
|
18
8
|
}),
|
|
19
9
|
transformToRequire: {
|
|
20
10
|
video: 'src',
|
|
@@ -13,8 +13,7 @@ const vueLoaderConfig = require('./vue-loader.conf');
|
|
|
13
13
|
const { resolve, resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
14
14
|
const getProjectDir = require('../utils/getProjectDir');
|
|
15
15
|
const catchVuePages = require('../utils/catchVuePages'); // 用于获取当前项目中的vue单文件
|
|
16
|
-
//
|
|
17
|
-
const projectConfig = require('../config/index');
|
|
16
|
+
const getProjectConfig = require('../config/index'); // 用于获取当前项目配置文件
|
|
18
17
|
const babelConfig = require('../config/babel.config'); // Babel的配置文件
|
|
19
18
|
const { buildBanner } = require('../utils/akfunParams');
|
|
20
19
|
const getJsEntries = require('../utils/jsEntries');
|
|
@@ -32,9 +31,9 @@ const BannerPack = new webpack.BannerPlugin({
|
|
|
32
31
|
* _curEnvConfig: 执行环境中的配置,用于记录 dev、build、build2lib 等对应的配置内容;
|
|
33
32
|
* _akfunConfig:完整的配置对象
|
|
34
33
|
*/
|
|
35
|
-
module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
34
|
+
module.exports = (_curEnvConfig, _akfunConfig, buildMode = 'build') => {
|
|
36
35
|
const curEnvConfig = _curEnvConfig || {}; // 用于接收当前运行环境配置变量
|
|
37
|
-
let config = _akfunConfig ||
|
|
36
|
+
let config = _akfunConfig || getProjectConfig(); // 优先使用外部传进来的项目配置
|
|
38
37
|
// 获取当前项目配置文件中的webpack配置
|
|
39
38
|
const curWebpackConfig = config.webpack;
|
|
40
39
|
// 获取当前项目目录
|
|
@@ -49,7 +48,20 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
49
48
|
curWebpackConfig.babelPlugins(babelConfig.plugins);
|
|
50
49
|
}
|
|
51
50
|
|
|
51
|
+
// 获取缓存目录路径
|
|
52
|
+
const cacheDirectory = resolveToCurrentRoot('./node_modules/.cache/webpack');
|
|
53
|
+
|
|
52
54
|
const webpackConfig = {
|
|
55
|
+
// Webpack 5 持久化缓存配置
|
|
56
|
+
cache: {
|
|
57
|
+
type: 'filesystem',
|
|
58
|
+
cacheDirectory: cacheDirectory,
|
|
59
|
+
buildDependencies: {
|
|
60
|
+
config: [__filename] // 当配置文件改变时,使缓存失效
|
|
61
|
+
},
|
|
62
|
+
name: `${curEnvConfig.NODE_ENV || 'development'}--${buildMode}-cache`,
|
|
63
|
+
compression: 'gzip' // 使用 gzip 压缩缓存文件以节省磁盘空间
|
|
64
|
+
},
|
|
53
65
|
stats: {
|
|
54
66
|
// cachedModules: false,
|
|
55
67
|
// providedExports: true,
|
|
@@ -86,7 +98,7 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
86
98
|
use: [
|
|
87
99
|
{
|
|
88
100
|
loader: 'vue-loader',
|
|
89
|
-
options: vueLoaderConfig(curEnvConfig) // 配置vue-loader相关的loader插件
|
|
101
|
+
options: vueLoaderConfig(curEnvConfig, curWebpackConfig) // 配置vue-loader相关的loader插件
|
|
90
102
|
}
|
|
91
103
|
]
|
|
92
104
|
},
|
|
@@ -96,7 +108,13 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
96
108
|
use: [
|
|
97
109
|
{
|
|
98
110
|
loader: 'babel-loader',
|
|
99
|
-
options:
|
|
111
|
+
options: {
|
|
112
|
+
...babelConfig,
|
|
113
|
+
// Babel 缓存配置
|
|
114
|
+
cacheDirectory: true, // 启用缓存
|
|
115
|
+
cacheCompression: false, // 不压缩缓存文件以提升性能
|
|
116
|
+
cacheIdentifier: `${curEnvConfig.NODE_ENV || 'development'}--${buildMode}-babel`
|
|
117
|
+
}
|
|
100
118
|
},
|
|
101
119
|
{
|
|
102
120
|
loader: 'ts-loader',
|
|
@@ -105,7 +123,11 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
105
123
|
compilerOptions: {
|
|
106
124
|
declaration: curWebpackConfig.createDeclaration || false,
|
|
107
125
|
outDir: curEnvConfig.assetsRoot || './dist'
|
|
108
|
-
}
|
|
126
|
+
},
|
|
127
|
+
// TypeScript 缓存配置
|
|
128
|
+
transpileOnly: true, // 只进行转译,不进行类型检查(提升性能)
|
|
129
|
+
experimentalWatchApi: true // 使用实验性的 watch API(提升性能)
|
|
130
|
+
// 注意:ts-loader 的缓存由 Webpack 5 的持久化缓存自动处理
|
|
109
131
|
}
|
|
110
132
|
}
|
|
111
133
|
],
|
|
@@ -117,7 +139,13 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
117
139
|
use: [
|
|
118
140
|
{
|
|
119
141
|
loader: 'babel-loader',
|
|
120
|
-
options:
|
|
142
|
+
options: {
|
|
143
|
+
...babelConfig,
|
|
144
|
+
// Babel 缓存配置
|
|
145
|
+
cacheDirectory: true, // 启用缓存
|
|
146
|
+
cacheCompression: false, // 不压缩缓存文件以提升性能
|
|
147
|
+
cacheIdentifier: `${curEnvConfig.NODE_ENV || 'development'}--${buildMode}-babel`
|
|
148
|
+
}
|
|
121
149
|
}
|
|
122
150
|
],
|
|
123
151
|
// exclude: /node_modules/,
|
|
@@ -273,6 +301,9 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
273
301
|
}
|
|
274
302
|
// 是否开启ESLint
|
|
275
303
|
if (config.settings.enableESLint) {
|
|
304
|
+
// ESLint 缓存目录
|
|
305
|
+
const eslintCacheLocation = resolveToCurrentRoot('./node_modules/.cache/eslint');
|
|
306
|
+
|
|
276
307
|
// ts类型
|
|
277
308
|
webpackConfig.plugins.push(
|
|
278
309
|
new ESLintPlugin({
|
|
@@ -280,7 +311,9 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
280
311
|
extensions: ['ts', 'tsx'],
|
|
281
312
|
// include: curProjectDir, // [resolve('src')],
|
|
282
313
|
// exclude: 'node_modules',
|
|
283
|
-
cache: true,
|
|
314
|
+
cache: true, // 启用缓存
|
|
315
|
+
cacheLocation: path.join(eslintCacheLocation, '.eslintcache-ts'), // 指定缓存位置
|
|
316
|
+
cacheStrategy: 'metadata', // 使用元数据缓存策略(更快)
|
|
284
317
|
fix: config.settings.enableESLintFix || false,
|
|
285
318
|
formatter: require('eslint-friendly-formatter'),
|
|
286
319
|
overrideConfigFile: path.resolve(__dirname, '../config/.eslintrc.ts.js')
|
|
@@ -292,7 +325,9 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
292
325
|
extensions: ['js', 'jsx'],
|
|
293
326
|
// include: curProjectDir, // [resolve('src')],
|
|
294
327
|
// exclude: 'node_modules',
|
|
295
|
-
cache: true,
|
|
328
|
+
cache: true, // 启用缓存
|
|
329
|
+
cacheLocation: path.join(eslintCacheLocation, '.eslintcache-js'), // 指定缓存位置
|
|
330
|
+
cacheStrategy: 'metadata', // 使用元数据缓存策略(更快)
|
|
296
331
|
fix: config.settings.enableESLintFix || false,
|
|
297
332
|
formatter: require('eslint-friendly-formatter'),
|
|
298
333
|
overrideConfigFile: path.resolve(__dirname, '../config/.eslintrc.js')
|
|
@@ -304,7 +339,9 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
304
339
|
extensions: ['vue'],
|
|
305
340
|
// include: curProjectDir, // [resolve('src')],
|
|
306
341
|
// exclude: 'node_modules',
|
|
307
|
-
cache: true,
|
|
342
|
+
cache: true, // 启用缓存
|
|
343
|
+
cacheLocation: path.join(eslintCacheLocation, '.eslintcache-vue'), // 指定缓存位置
|
|
344
|
+
cacheStrategy: 'metadata', // 使用元数据缓存策略(更快)
|
|
308
345
|
fix: config.settings.enableESLintFix || false,
|
|
309
346
|
formatter: require('eslint-friendly-formatter'),
|
|
310
347
|
overrideConfigFile: path.resolve(__dirname, '../config/.eslintrc.vue.js')
|
|
@@ -313,6 +350,9 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
313
350
|
}
|
|
314
351
|
// 是否开启StyleLint: 用于验证scss文件里面的style规范
|
|
315
352
|
if (config.settings.enableStyleLint) {
|
|
353
|
+
// StyleLint 缓存目录
|
|
354
|
+
const stylelintCacheLocation = resolveToCurrentRoot('./node_modules/.cache/stylelint');
|
|
355
|
+
|
|
316
356
|
const vuePagesObj = catchVuePages();
|
|
317
357
|
// 判断项目中是否有vue文件
|
|
318
358
|
if (vuePagesObj && Object.keys(vuePagesObj).length > 0) {
|
|
@@ -321,8 +361,8 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
321
361
|
new StyleLintPlugin({
|
|
322
362
|
files: ['src/**/*.vue'],
|
|
323
363
|
// quiet: true,
|
|
324
|
-
cache: true,
|
|
325
|
-
cacheLocation:
|
|
364
|
+
cache: true, // 启用缓存
|
|
365
|
+
cacheLocation: path.join(stylelintCacheLocation, '.stylelintcache-vue'), // 统一缓存位置
|
|
326
366
|
fix: config.settings.enableStyleLintFix,
|
|
327
367
|
configFile: path.resolve(__dirname, '../config/.stylelintrc-vue')
|
|
328
368
|
})
|
|
@@ -333,8 +373,8 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
|
333
373
|
new StyleLintPlugin({
|
|
334
374
|
files: 'src/**/*.s?(a|c)ss',
|
|
335
375
|
// quiet: true,
|
|
336
|
-
cache: true,
|
|
337
|
-
cacheLocation:
|
|
376
|
+
cache: true, // 启用缓存
|
|
377
|
+
cacheLocation: path.join(stylelintCacheLocation, '.stylelintcache-scss'), // 统一缓存位置
|
|
338
378
|
fix: config.settings.enableStyleLintFix,
|
|
339
379
|
configFile: path.resolve(__dirname, '../config/.stylelintrc')
|
|
340
380
|
})
|
|
@@ -3,27 +3,27 @@ const path = require('path');
|
|
|
3
3
|
const { merge } = require('webpack-merge');
|
|
4
4
|
const utils = require('./loaderUtils');
|
|
5
5
|
const getBaseWebpackConfig = require('./webpack.base.conf'); // 获取webpack基本配置
|
|
6
|
-
//
|
|
7
|
-
const projectConfig = require('../config/index');
|
|
6
|
+
const getProjectConfig = require('../config/index'); // 用于获取当前项目配置文件
|
|
8
7
|
const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
|
|
9
8
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
10
9
|
// const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
|
11
10
|
|
|
12
11
|
module.exports = (akfunConfig) => {
|
|
13
|
-
let config = akfunConfig ||
|
|
12
|
+
let config = akfunConfig || getProjectConfig(); // 优先使用外部传进来的项目配置
|
|
14
13
|
const curEnvConfig = config.dev || {}; // 当前执行环境配置
|
|
15
14
|
// 获取webpack基本配置
|
|
16
|
-
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
|
|
15
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config, 'dev');
|
|
16
|
+
const curWebpackConfig = config.webpack || {};
|
|
17
17
|
|
|
18
18
|
// 获取页面模板地址
|
|
19
19
|
let curHtmlTemplate = path.resolve(__dirname, '../initData/template/index.html');
|
|
20
|
-
if (
|
|
21
|
-
curHtmlTemplate =
|
|
20
|
+
if (curWebpackConfig.template) {
|
|
21
|
+
curHtmlTemplate = curWebpackConfig.template; // akfun.config.js中的webpack配置
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
let curTarget = ['web', 'es5'];
|
|
25
|
-
if (
|
|
26
|
-
curTarget =
|
|
25
|
+
if (curWebpackConfig.target) {
|
|
26
|
+
curTarget = curWebpackConfig.target; // akfun.config.js中的webpack配置
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const webpackDevConfig = merge(baseWebpackConfig, {
|
|
@@ -40,12 +40,7 @@ module.exports = (akfunConfig) => {
|
|
|
40
40
|
module: {
|
|
41
41
|
rules: utils.styleLoaders({
|
|
42
42
|
envConfig: curEnvConfig, // 当前环境变量
|
|
43
|
-
|
|
44
|
-
environment: 'prod', // 'dev': 不会将css单独提取出来
|
|
45
|
-
cssLoaderUrl: config.webpack.cssLoaderUrl,
|
|
46
|
-
cssLoaderUrlDir: config.webpack.cssLoaderUrlDir,
|
|
47
|
-
cssLoaderOption: config.webpack.cssLoaderOption, // 用于自定义css-loader配置项(优先级最高)
|
|
48
|
-
postCssLoaderOption: config.webpack.postCssLoaderOption // 用于自定义postcss-loader配置项(优先级最高)
|
|
43
|
+
webpackConfig: curWebpackConfig, // 当前webpack配置
|
|
49
44
|
})
|
|
50
45
|
},
|
|
51
46
|
// devtool: '#cheap-module-eval-source-map', // 本地开发环境中的取值
|
|
@@ -6,8 +6,7 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl
|
|
|
6
6
|
const deepMergeConfig = require('../utils/deepMergeConfig');
|
|
7
7
|
|
|
8
8
|
const utils = require('./loaderUtils');
|
|
9
|
-
//
|
|
10
|
-
const projectConfig = require('../config/index');
|
|
9
|
+
const getProjectConfig = require('../config/index'); // 用于获取当前项目配置文件
|
|
11
10
|
const getBaseWebpackConfig = require('./webpack.base.conf');
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -16,14 +15,15 @@ const getBaseWebpackConfig = require('./webpack.base.conf');
|
|
|
16
15
|
* @returns
|
|
17
16
|
*/
|
|
18
17
|
module.exports = (akfunConfig) => {
|
|
19
|
-
let config = akfunConfig ||
|
|
18
|
+
let config = akfunConfig || getProjectConfig(); // 优先使用外部传进来的项目配置
|
|
20
19
|
const curEnvConfig = config.build2lib || {}; // 当前执行环境配置
|
|
21
20
|
// 获取webpack基本配置
|
|
22
|
-
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
|
|
21
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config, 'build2lib');
|
|
22
|
+
const curWebpackConfig = config.webpack || {};
|
|
23
23
|
|
|
24
24
|
let curTarget = ['web', 'es5'];
|
|
25
|
-
if (
|
|
26
|
-
curTarget =
|
|
25
|
+
if (curWebpackConfig.target) {
|
|
26
|
+
curTarget = curWebpackConfig.target; // akfun.config.js中的webpack配置
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const webpackLibConfig = merge(baseWebpackConfig, {
|
|
@@ -43,12 +43,7 @@ module.exports = (akfunConfig) => {
|
|
|
43
43
|
module: {
|
|
44
44
|
rules: utils.styleLoaders({
|
|
45
45
|
envConfig: curEnvConfig, // 当前环境变量
|
|
46
|
-
|
|
47
|
-
environment: 'prod',
|
|
48
|
-
cssLoaderUrl: config.webpack.cssLoaderUrl,
|
|
49
|
-
cssLoaderUrlDir: config.webpack.cssLoaderUrlDir,
|
|
50
|
-
cssLoaderOption: config.webpack.cssLoaderOption, // 用于自定义css-loader配置项(优先级最高)
|
|
51
|
-
postCssLoaderOption: config.webpack.postCssLoaderOption // 用于自定义postcss-loader配置项(优先级最高)
|
|
46
|
+
webpackConfig: curWebpackConfig, // 当前webpack配置
|
|
52
47
|
})
|
|
53
48
|
},
|
|
54
49
|
devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'source-map' : false, // 线上生成环境
|
|
@@ -11,8 +11,7 @@ const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
|
|
11
11
|
const utils = require('./loaderUtils');
|
|
12
12
|
const { resolve } = require('../utils/pathUtils'); // 统一路径解析
|
|
13
13
|
const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
|
|
14
|
-
//
|
|
15
|
-
const projectConfig = require('../config/index');
|
|
14
|
+
const getProjectConfig = require('../config/index'); // 用于获取当前项目配置文件
|
|
16
15
|
const getBaseWebpackConfig = require('./webpack.base.conf');
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -21,19 +20,20 @@ const getBaseWebpackConfig = require('./webpack.base.conf');
|
|
|
21
20
|
* @returns
|
|
22
21
|
*/
|
|
23
22
|
module.exports = (akfunConfig) => {
|
|
24
|
-
let config = akfunConfig ||
|
|
23
|
+
let config = akfunConfig || getProjectConfig(); // 默认使用执行命令目录下的配置数据
|
|
25
24
|
const curEnvConfig = config.build || {}; // 当前执行环境配置
|
|
26
25
|
// 获取webpack基本配置
|
|
27
|
-
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
|
|
26
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config, 'build');
|
|
27
|
+
const curWebpackConfig = config.webpack || {};
|
|
28
28
|
// 获取页面模板地址
|
|
29
29
|
let curHtmlTemplate = path.resolve(__dirname, '../initData/template/index.html');
|
|
30
|
-
if (
|
|
31
|
-
curHtmlTemplate =
|
|
30
|
+
if (curWebpackConfig.template) {
|
|
31
|
+
curHtmlTemplate = curWebpackConfig.template; // akfun.config.js中的webpack配置
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let curTarget = ['web', 'es5'];
|
|
35
|
-
if (
|
|
36
|
-
curTarget =
|
|
35
|
+
if (curWebpackConfig.target) {
|
|
36
|
+
curTarget = curWebpackConfig.target; // akfun.config.js中的webpack配置
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const webpackProdConfig = merge(baseWebpackConfig, {
|
|
@@ -56,12 +56,7 @@ module.exports = (akfunConfig) => {
|
|
|
56
56
|
module: {
|
|
57
57
|
rules: utils.styleLoaders({
|
|
58
58
|
envConfig: curEnvConfig, // 当前环境变量
|
|
59
|
-
|
|
60
|
-
environment: 'prod',
|
|
61
|
-
cssLoaderUrl: config.webpack.cssLoaderUrl,
|
|
62
|
-
cssLoaderUrlDir: config.webpack.cssLoaderUrlDir,
|
|
63
|
-
cssLoaderOption: config.webpack.cssLoaderOption, // 用于自定义css-loader配置项(优先级最高)
|
|
64
|
-
postCssLoaderOption: config.webpack.postCssLoaderOption // 用于自定义postcss-loader配置项(优先级最高)
|
|
59
|
+
webpackConfig: curWebpackConfig, // 当前webpack配置
|
|
65
60
|
})
|
|
66
61
|
},
|
|
67
62
|
devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'source-map' : false, // 线上生成环境
|