akfun 1.6.10 → 2.0.1
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akfun",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "前端脚手架:支持Vue技术栈和react技术栈",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"前端工程",
|
|
@@ -147,9 +147,9 @@
|
|
|
147
147
|
"vue-loader": "^15.9.2",
|
|
148
148
|
"vue-style-loader": "^4.1.2",
|
|
149
149
|
"vue-template-compiler": "^2.6.11",
|
|
150
|
-
"webpack": "^
|
|
150
|
+
"webpack": "^5.65.0",
|
|
151
151
|
"webpack-bundle-analyzer": "^3.8.0",
|
|
152
|
-
"webpack-cli": "^
|
|
152
|
+
"webpack-cli": "^4.9.1",
|
|
153
153
|
"webpack-dev-middleware": "^3.7.2",
|
|
154
154
|
"webpack-hot-middleware": "^2.25.0",
|
|
155
155
|
"webpack-merge": "^4.2.2",
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
2
3
|
const webpack = require('webpack');
|
|
3
4
|
// const tsImportPluginFactory = require('ts-import-plugin'); // 按需加载lib库组件代码
|
|
4
5
|
const StyleLintPlugin = require('stylelint-webpack-plugin');
|
|
5
6
|
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
|
6
7
|
const nodeExternals = require('webpack-node-externals');
|
|
8
|
+
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
|
|
9
|
+
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
|
7
10
|
const utils = require('./loaderUtils');
|
|
8
11
|
const vueLoaderConfig = require('./vue-loader.conf');
|
|
9
12
|
const { resolve, resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
10
13
|
const getProjectDir = require('../utils/getProjectDir');
|
|
11
14
|
const catchVuePages = require('../utils/catchVuePages'); // 用于获取当前项目中的vue单文件
|
|
12
15
|
// 引入当前项目配置文件
|
|
13
|
-
const
|
|
16
|
+
const projectConfig = require('../config/index');
|
|
14
17
|
const babelConfig = require('../config/babel.config'); // Babel的配置文件
|
|
15
18
|
const {buildBanner} = require("../utils/akfunParams");
|
|
16
19
|
const getJsEntries = require('../utils/jsEntries');
|
|
17
20
|
const { isArray } = require('../utils/typeof');
|
|
18
|
-
const fs = require('fs');
|
|
19
|
-
|
|
20
21
|
|
|
21
22
|
// 生成构建头部信息
|
|
22
23
|
const BannerPack = new webpack.BannerPlugin({
|
|
@@ -27,14 +28,20 @@ const BannerPack = new webpack.BannerPlugin({
|
|
|
27
28
|
/**
|
|
28
29
|
* webpack.base.conf.js
|
|
29
30
|
* 主要用于设置 rules 和 通用插件
|
|
31
|
+
* _curEnvConfig: 执行环境中的配置,比如:dev、build、build2lib等;
|
|
32
|
+
* _akfunConfig:完整的配置对象
|
|
30
33
|
*/
|
|
31
|
-
module.exports = (_curEnvConfig,
|
|
34
|
+
module.exports = (_curEnvConfig, _akfunConfig) => {
|
|
32
35
|
const curEnvConfig = _curEnvConfig || {}; // 用于接收当前运行环境配置变量
|
|
33
|
-
|
|
36
|
+
let config = _akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
|
|
37
|
+
const curWebpackConfig = config.webpack;
|
|
34
38
|
// 获取当前项目目录
|
|
35
39
|
const curProjectDir = getProjectDir(curWebpackConfig.projectDir);
|
|
36
40
|
const webpackConfig = {
|
|
37
41
|
entry: curWebpackConfig.entry,
|
|
42
|
+
// target: 'web', // <=== 默认为 'web',可省略
|
|
43
|
+
target: ['web', 'es5'], // 使用共同的特性子集
|
|
44
|
+
// target: false, // 不使用任何插件
|
|
38
45
|
/*
|
|
39
46
|
内置变量列表:
|
|
40
47
|
id: chunk的唯一标识,从0开始;
|
|
@@ -50,11 +57,11 @@ module.exports = (_curEnvConfig, _curWebpackConfig) => {
|
|
|
50
57
|
* 当webpack试图去加载模块的时候,它默认是查找以 .js 结尾的文件的
|
|
51
58
|
*/
|
|
52
59
|
resolve: curWebpackConfig.resolve,
|
|
53
|
-
externals:
|
|
60
|
+
externals: curWebpackConfig.ignoreNodeModules
|
|
54
61
|
? [nodeExternals({
|
|
55
|
-
allowlist:
|
|
56
|
-
})].concat(
|
|
57
|
-
:
|
|
62
|
+
allowlist: curWebpackConfig.allowList ? curWebpackConfig.allowList : []
|
|
63
|
+
})].concat(curWebpackConfig.externals)
|
|
64
|
+
: curWebpackConfig.externals,
|
|
58
65
|
module: {
|
|
59
66
|
rules: [
|
|
60
67
|
{
|
|
@@ -146,16 +153,22 @@ module.exports = (_curEnvConfig, _curWebpackConfig) => {
|
|
|
146
153
|
},
|
|
147
154
|
plugins: [
|
|
148
155
|
BannerPack,
|
|
156
|
+
new webpack.DefinePlugin({
|
|
157
|
+
'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV)
|
|
158
|
+
}),
|
|
149
159
|
// 请确保引入这个插件来施展魔法
|
|
150
|
-
new VueLoaderPlugin()
|
|
160
|
+
new VueLoaderPlugin(),
|
|
161
|
+
new FriendlyErrorsPlugin(),
|
|
162
|
+
new ProgressBarPlugin()
|
|
151
163
|
]
|
|
152
164
|
};
|
|
153
165
|
// 优先使用执行环境中的配置
|
|
154
|
-
if (curEnvConfig.ignoreNodeModules) {
|
|
155
|
-
const allowList = curEnvConfig.allowList ||
|
|
156
|
-
|
|
166
|
+
if (curEnvConfig.ignoreNodeModules !== undefined) {
|
|
167
|
+
const allowList = curEnvConfig.allowList || curWebpackConfig.allowList;
|
|
168
|
+
const externals = curEnvConfig.externals || config.webpack.external || [];
|
|
169
|
+
webpackConfig.externals = curEnvConfig.ignoreNodeModules ? [nodeExternals({
|
|
157
170
|
allowlist: allowList || [],
|
|
158
|
-
})].concat(
|
|
171
|
+
})].concat(externals) : externals;
|
|
159
172
|
}
|
|
160
173
|
// 集成构建入口相关的配置(优先级更高)
|
|
161
174
|
if (curEnvConfig.entry) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
const webpack = require('webpack');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const merge = require('webpack-merge');
|
|
4
|
-
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
|
|
5
|
-
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
|
6
4
|
const utils = require('./loaderUtils');
|
|
7
5
|
// 引入当前项目配置文件
|
|
8
6
|
const projectConfig = require('../config/index');
|
|
@@ -13,7 +11,7 @@ module.exports = (akfunConfig) => {
|
|
|
13
11
|
let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
|
|
14
12
|
const curEnvConfig = config.dev || {}; // 当前执行环境配置
|
|
15
13
|
// 获取webpack基本配置
|
|
16
|
-
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config
|
|
14
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
|
|
17
15
|
|
|
18
16
|
// 获取页面模板地址
|
|
19
17
|
let curHtmlTemplate = path.resolve(__dirname, '../initData/template/index.html');
|
|
@@ -32,17 +30,32 @@ module.exports = (akfunConfig) => {
|
|
|
32
30
|
environment: 'dev'
|
|
33
31
|
})
|
|
34
32
|
},
|
|
35
|
-
// cheap-module-eval-source-map
|
|
36
|
-
devtool: '
|
|
33
|
+
// devtool: '#cheap-module-eval-source-map', // 本地开发环境中的取值
|
|
34
|
+
devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'eval-source-map' : 'eval', // 开发环境
|
|
35
|
+
optimization: {
|
|
36
|
+
chunkIds: 'named', // named 对调试更友好的可读的 id。
|
|
37
|
+
emitOnErrors: true,
|
|
38
|
+
splitChunks: {
|
|
39
|
+
cacheGroups: {
|
|
40
|
+
defaultVendors: { // 4.0: vendors
|
|
41
|
+
test: /node_modules\/(.*)/,
|
|
42
|
+
name: 'vendor',
|
|
43
|
+
chunks: 'initial',
|
|
44
|
+
reuseExistingChunk: true
|
|
45
|
+
},
|
|
46
|
+
common: {
|
|
47
|
+
name: 'common',
|
|
48
|
+
minChunks: 2,
|
|
49
|
+
priority: -20,
|
|
50
|
+
chunks: 'initial',
|
|
51
|
+
reuseExistingChunk: true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
37
56
|
plugins: [
|
|
38
|
-
new webpack.DefinePlugin({
|
|
39
|
-
'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV) // vue-router中根据此变量判断执行环境
|
|
40
|
-
}),
|
|
41
57
|
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
|
|
42
58
|
new webpack.HotModuleReplacementPlugin(),
|
|
43
|
-
new webpack.NoEmitOnErrorsPlugin(),
|
|
44
|
-
new FriendlyErrorsPlugin(),
|
|
45
|
-
new ProgressBarPlugin()
|
|
46
59
|
]
|
|
47
60
|
});
|
|
48
61
|
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
const webpack = require('webpack');
|
|
2
1
|
const merge = require('webpack-merge');
|
|
3
2
|
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
|
|
4
3
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // 替换extract-text-webpack-plugin
|
|
5
4
|
const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
|
6
5
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
7
|
-
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
|
|
8
|
-
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
|
9
6
|
|
|
10
7
|
const utils = require('./loaderUtils');
|
|
11
8
|
// 引入当前项目配置文件
|
|
@@ -16,17 +13,20 @@ module.exports = (akfunConfig) => {
|
|
|
16
13
|
let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
|
|
17
14
|
const curEnvConfig = config.build2lib || {}; // 当前执行环境配置
|
|
18
15
|
// 获取webpack基本配置
|
|
19
|
-
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config
|
|
16
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
|
|
20
17
|
|
|
21
18
|
const webpackLibConfig = merge(baseWebpackConfig, {
|
|
22
19
|
mode: curEnvConfig.NODE_ENV, // production 模式,会启动UglifyJsPlugin服务
|
|
23
20
|
output: {
|
|
24
21
|
path: curEnvConfig.assetsRoot, // 输出文件的存放在本地的目录
|
|
25
|
-
filename: '
|
|
22
|
+
filename: 'index.umd.js',
|
|
26
23
|
publicPath: '',
|
|
27
|
-
library:
|
|
24
|
+
library: {
|
|
25
|
+
type: 'umd', // 定义打包方式Universal Module Definition,同时支持在CommonJS、AMD和全局变量使用
|
|
26
|
+
name: curEnvConfig.libraryName,
|
|
27
|
+
},
|
|
28
|
+
// 指定类库名,主要用于直接引用的方式(比如使用script 标签)
|
|
28
29
|
globalObject: 'this', // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
|
|
29
|
-
libraryTarget: 'umd' // 定义打包方式Universal Module Definition,同时支持在CommonJS、AMD和全局变量使用
|
|
30
30
|
},
|
|
31
31
|
module: {
|
|
32
32
|
rules: utils.styleLoaders({
|
|
@@ -34,11 +34,16 @@ module.exports = (akfunConfig) => {
|
|
|
34
34
|
environment: 'prod'
|
|
35
35
|
})
|
|
36
36
|
},
|
|
37
|
-
devtool:
|
|
37
|
+
devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'source-map' : false, // 线上生成环境
|
|
38
|
+
optimization: {
|
|
39
|
+
/**
|
|
40
|
+
* named 对调试更友好的可读的 id。
|
|
41
|
+
* deterministic 在不同的编译中不变的短数字 id。有益于长期缓存。在生产模式中会默认开启。
|
|
42
|
+
*/
|
|
43
|
+
chunkIds: 'named',
|
|
44
|
+
emitOnErrors: true
|
|
45
|
+
},
|
|
38
46
|
plugins: [
|
|
39
|
-
new webpack.DefinePlugin({
|
|
40
|
-
'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV)
|
|
41
|
-
}),
|
|
42
47
|
new MiniCssExtractPlugin({
|
|
43
48
|
// filename: utils.assetsPath('index.css'),
|
|
44
49
|
filename: "[name].css",
|
|
@@ -50,8 +55,6 @@ module.exports = (akfunConfig) => {
|
|
|
50
55
|
safe: true
|
|
51
56
|
}
|
|
52
57
|
}),
|
|
53
|
-
new FriendlyErrorsPlugin(),
|
|
54
|
-
new ProgressBarPlugin()
|
|
55
58
|
]
|
|
56
59
|
});
|
|
57
60
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const webpack = require('webpack');
|
|
4
3
|
const merge = require('webpack-merge');
|
|
5
4
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
6
5
|
// const ExtractTextPlugin = require('extract-text-webpack-plugin'); // 不支持webpack4.0
|
|
@@ -8,8 +7,6 @@ const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
|
|
|
8
7
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // 替换extract-text-webpack-plugin
|
|
9
8
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
10
9
|
const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
|
11
|
-
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
|
|
12
|
-
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
|
13
10
|
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
14
11
|
|
|
15
12
|
const utils = require('./loaderUtils');
|
|
@@ -23,7 +20,7 @@ module.exports = (akfunConfig) => {
|
|
|
23
20
|
let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
|
|
24
21
|
const curEnvConfig = config.build || {}; // 当前执行环境配置
|
|
25
22
|
// 获取webpack基本配置
|
|
26
|
-
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config
|
|
23
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
|
|
27
24
|
// 获取页面模板地址
|
|
28
25
|
let curHtmlTemplate = path.resolve(__dirname, '../initData/template/index.html');
|
|
29
26
|
if (config.webpack.template) {
|
|
@@ -52,12 +49,13 @@ module.exports = (akfunConfig) => {
|
|
|
52
49
|
environment: 'prod'
|
|
53
50
|
})
|
|
54
51
|
},
|
|
55
|
-
|
|
56
|
-
devtool: curEnvConfig.productionSourceMap ? '#source-map' : false, // 线上开发环境中的取值
|
|
52
|
+
devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'source-map' : false, // 线上生成环境
|
|
57
53
|
optimization: {
|
|
54
|
+
chunkIds: 'deterministic', // 在不同的编译中不变的短数字 id。有益于长期缓存。在生产模式中会默认开启。
|
|
55
|
+
emitOnErrors: true,
|
|
58
56
|
splitChunks: {
|
|
59
57
|
cacheGroups: {
|
|
60
|
-
|
|
58
|
+
defaultVendors: { // 4.0: vendors
|
|
61
59
|
test: /node_modules\/(.*)/,
|
|
62
60
|
name: 'vendor',
|
|
63
61
|
chunks: 'initial',
|
|
@@ -74,10 +72,6 @@ module.exports = (akfunConfig) => {
|
|
|
74
72
|
}
|
|
75
73
|
},
|
|
76
74
|
plugins: [
|
|
77
|
-
// http://vuejs.github.io/vue-loader/en/workflow/production.html
|
|
78
|
-
new webpack.DefinePlugin({
|
|
79
|
-
'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV) // vue-router中根据此变量判断执行环境
|
|
80
|
-
}),
|
|
81
75
|
new MiniCssExtractPlugin({
|
|
82
76
|
filename: utils.assetsPath('css/[name].[contenthash:8].css'),
|
|
83
77
|
ignoreOrder: false // Enable to remove warnings about conflicting order
|
|
@@ -97,8 +91,6 @@ module.exports = (akfunConfig) => {
|
|
|
97
91
|
safe: true
|
|
98
92
|
}
|
|
99
93
|
}),
|
|
100
|
-
new FriendlyErrorsPlugin(),
|
|
101
|
-
new ProgressBarPlugin()
|
|
102
94
|
]
|
|
103
95
|
});
|
|
104
96
|
|