akfun 1.6.12 → 2.0.3

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": "1.6.12",
3
+ "version": "2.0.3",
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": "^4.43.0",
150
+ "webpack": "^5.65.0",
151
151
  "webpack-bundle-analyzer": "^3.8.0",
152
- "webpack-cli": "^3.3.11",
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",
@@ -5,6 +5,8 @@ const webpack = require('webpack');
5
5
  const StyleLintPlugin = require('stylelint-webpack-plugin');
6
6
  const VueLoaderPlugin = require('vue-loader/lib/plugin');
7
7
  const nodeExternals = require('webpack-node-externals');
8
+ const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
9
+ const ProgressBarPlugin = require('progress-bar-webpack-plugin');
8
10
  const utils = require('./loaderUtils');
9
11
  const vueLoaderConfig = require('./vue-loader.conf');
10
12
  const { resolve, resolveToCurrentRoot } = require('../utils/pathUtils');
@@ -13,7 +15,7 @@ const catchVuePages = require('../utils/catchVuePages'); // 用于获取当前
13
15
  // 引入当前项目配置文件
14
16
  const projectConfig = require('../config/index');
15
17
  const babelConfig = require('../config/babel.config'); // Babel的配置文件
16
- const {buildBanner} = require("../utils/akfunParams");
18
+ const { buildBanner } = require('../utils/akfunParams');
17
19
  const getJsEntries = require('../utils/jsEntries');
18
20
  const { isArray } = require('../utils/typeof');
19
21
 
@@ -37,6 +39,9 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
37
39
  const curProjectDir = getProjectDir(curWebpackConfig.projectDir);
38
40
  const webpackConfig = {
39
41
  entry: curWebpackConfig.entry,
42
+ // target: 'web', // <=== 默认为 'web',可省略
43
+ target: ['web', 'es5'], // 使用共同的特性子集
44
+ // target: false, // 不使用任何插件
40
45
  /*
41
46
  内置变量列表:
42
47
  id: chunk的唯一标识,从0开始;
@@ -53,9 +58,12 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
53
58
  */
54
59
  resolve: curWebpackConfig.resolve,
55
60
  externals: curWebpackConfig.ignoreNodeModules
56
- ? [nodeExternals({
57
- allowlist: curWebpackConfig.allowList ? curWebpackConfig.allowList : []
58
- })].concat(curWebpackConfig.externals)
61
+ ? [
62
+ nodeExternals({
63
+ importType: 'commonjs',
64
+ allowlist: curWebpackConfig.allowList ? curWebpackConfig.allowList : []
65
+ })
66
+ ].concat(curWebpackConfig.externals)
59
67
  : curWebpackConfig.externals,
60
68
  module: {
61
69
  rules: [
@@ -148,16 +156,27 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
148
156
  },
149
157
  plugins: [
150
158
  BannerPack,
159
+ new webpack.DefinePlugin({
160
+ 'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV)
161
+ }),
151
162
  // 请确保引入这个插件来施展魔法
152
- new VueLoaderPlugin()
163
+ new VueLoaderPlugin(),
164
+ new FriendlyErrorsPlugin(),
165
+ new ProgressBarPlugin()
153
166
  ]
154
167
  };
155
168
  // 优先使用执行环境中的配置
156
- if (curEnvConfig.ignoreNodeModules) {
169
+ if (curEnvConfig.ignoreNodeModules !== undefined) {
157
170
  const allowList = curEnvConfig.allowList || curWebpackConfig.allowList;
158
- webpackConfig.externals = [nodeExternals({
159
- allowlist: allowList || [],
160
- })].concat(curEnvConfig.externals || config.webpack.externals);
171
+ const externals = curEnvConfig.externals || config.webpack.external || [];
172
+ webpackConfig.externals = curEnvConfig.ignoreNodeModules
173
+ ? [
174
+ nodeExternals({
175
+ importType: 'commonjs',
176
+ allowlist: allowList || []
177
+ })
178
+ ].concat(externals)
179
+ : externals;
161
180
  }
162
181
  // 集成构建入口相关的配置(优先级更高)
163
182
  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');
@@ -32,17 +30,15 @@ module.exports = (akfunConfig) => {
32
30
  environment: 'dev'
33
31
  })
34
32
  },
35
- // cheap-module-eval-source-map is faster for development
36
- devtool: '#source-map', // '#cheap-module-eval-source-map',
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
+ },
37
39
  plugins: [
38
- new webpack.DefinePlugin({
39
- 'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV) // vue-router中根据此变量判断执行环境
40
- }),
41
40
  // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
42
- new webpack.HotModuleReplacementPlugin(),
43
- new webpack.NoEmitOnErrorsPlugin(),
44
- new FriendlyErrorsPlugin(),
45
- new ProgressBarPlugin()
41
+ new webpack.HotModuleReplacementPlugin()
46
42
  ]
47
43
  });
48
44
 
@@ -55,7 +51,7 @@ module.exports = (akfunConfig) => {
55
51
  // 开启热更新能力
56
52
  const devClientPath = path.resolve(__dirname, '../dev-client'); // 从akfun中获取
57
53
  // add hot-reload related code to entry chunks
58
- if (webpackDevConfig.entry) {
54
+ if (!curEnvConfig.closeHotReload && webpackDevConfig.entry) {
59
55
  Object.keys(webpackDevConfig.entry).forEach((name) => {
60
56
  webpackDevConfig.entry[name] = [devClientPath].concat(webpackDevConfig.entry[name]);
61
57
  });
@@ -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
  // 引入当前项目配置文件
@@ -22,11 +19,14 @@ module.exports = (akfunConfig) => {
22
19
  mode: curEnvConfig.NODE_ENV, // production 模式,会启动UglifyJsPlugin服务
23
20
  output: {
24
21
  path: curEnvConfig.assetsRoot, // 输出文件的存放在本地的目录
25
- filename: '[name].umd.js',
22
+ filename: 'index.umd.js',
26
23
  publicPath: '',
27
- library: curEnvConfig.libraryName, // 指定类库名,主要用于直接引用的方式(比如使用script 标签)
28
- globalObject: 'this', // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
29
- libraryTarget: 'umd' // 定义打包方式Universal Module Definition,同时支持在CommonJS、AMD和全局变量使用
24
+ library: {
25
+ type: 'umd', // 定义打包方式Universal Module Definition,同时支持在CommonJS、AMD和全局变量使用
26
+ name: curEnvConfig.libraryName
27
+ },
28
+ // 指定类库名,主要用于直接引用的方式(比如使用script 标签)
29
+ globalObject: 'this' // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
30
30
  },
31
31
  module: {
32
32
  rules: utils.styleLoaders({
@@ -34,24 +34,27 @@ module.exports = (akfunConfig) => {
34
34
  environment: 'prod'
35
35
  })
36
36
  },
37
- devtool: curEnvConfig.productionSourceMap ? '#source-map' : false, // '#source-map': 源码,false:压缩代码
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
- filename: "[name].css",
45
- chunkFilename: "[name].css",
49
+ filename: '[name].css',
50
+ chunkFilename: '[name].css',
46
51
  ignoreOrder: false
47
52
  }),
48
53
  new OptimizeCSSPlugin({
49
54
  cssProcessorOptions: {
50
55
  safe: true
51
56
  }
52
- }),
53
- new FriendlyErrorsPlugin(),
54
- new ProgressBarPlugin()
57
+ })
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');
@@ -52,12 +49,14 @@ module.exports = (akfunConfig) => {
52
49
  environment: 'prod'
53
50
  })
54
51
  },
55
- // devtool: '#cheap-module-eval-source-map', // 本地开发环境中的取值
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
- vendors: {
58
+ defaultVendors: {
59
+ // 4.0: vendors
61
60
  test: /node_modules\/(.*)/,
62
61
  name: 'vendor',
63
62
  chunks: 'initial',
@@ -74,10 +73,6 @@ module.exports = (akfunConfig) => {
74
73
  }
75
74
  },
76
75
  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
76
  new MiniCssExtractPlugin({
82
77
  filename: utils.assetsPath('css/[name].[contenthash:8].css'),
83
78
  ignoreOrder: false // Enable to remove warnings about conflicting order
@@ -96,9 +91,7 @@ module.exports = (akfunConfig) => {
96
91
  cssProcessorOptions: {
97
92
  safe: true
98
93
  }
99
- }),
100
- new FriendlyErrorsPlugin(),
101
- new ProgressBarPlugin()
94
+ })
102
95
  ]
103
96
  });
104
97
 
@@ -136,7 +129,7 @@ module.exports = (akfunConfig) => {
136
129
  })
137
130
  );
138
131
  }
139
-
132
+
140
133
  // 是否开启
141
134
  if (curEnvConfig.openMonacoWebpackPlugin) {
142
135
  webpackProdConfig.plugins.push(new MonacoWebpackPlugin());