akfun 1.6.9 → 1.6.13

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 CHANGED
@@ -253,6 +253,7 @@ module.exports = {
253
253
  ...
254
254
  webpack: {
255
255
  ignoreNodeModules: true,
256
+ allowList: [], // 用于配置会注入bundle中的依赖包(ignoreNodeModules为true时生效)
256
257
  }
257
258
  ...
258
259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akfun",
3
- "version": "1.6.9",
3
+ "version": "1.6.13",
4
4
  "description": "前端脚手架:支持Vue技术栈和react技术栈",
5
5
  "keywords": [
6
6
  "前端工程",
@@ -1,18 +1,21 @@
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');
7
+ const nodeExternals = require('webpack-node-externals');
6
8
  const utils = require('./loaderUtils');
7
9
  const vueLoaderConfig = require('./vue-loader.conf');
8
10
  const { resolve, resolveToCurrentRoot } = require('../utils/pathUtils');
9
11
  const getProjectDir = require('../utils/getProjectDir');
10
12
  const catchVuePages = require('../utils/catchVuePages'); // 用于获取当前项目中的vue单文件
11
13
  // 引入当前项目配置文件
12
- const config = require('../config/index');
14
+ const projectConfig = require('../config/index');
13
15
  const babelConfig = require('../config/babel.config'); // Babel的配置文件
14
16
  const {buildBanner} = require("../utils/akfunParams");
15
-
17
+ const getJsEntries = require('../utils/jsEntries');
18
+ const { isArray } = require('../utils/typeof');
16
19
 
17
20
  // 生成构建头部信息
18
21
  const BannerPack = new webpack.BannerPlugin({
@@ -23,10 +26,13 @@ const BannerPack = new webpack.BannerPlugin({
23
26
  /**
24
27
  * webpack.base.conf.js
25
28
  * 主要用于设置 rules 和 通用插件
29
+ * _curEnvConfig: 执行环境中的配置,比如:dev、build、build2lib等;
30
+ * _akfunConfig:完整的配置对象
26
31
  */
27
- module.exports = (_curEnvConfig, _curWebpackConfig) => {
32
+ module.exports = (_curEnvConfig, _akfunConfig) => {
28
33
  const curEnvConfig = _curEnvConfig || {}; // 用于接收当前运行环境配置变量
29
- const curWebpackConfig = _curWebpackConfig || config.webpack;
34
+ let config = _akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
35
+ const curWebpackConfig = config.webpack;
30
36
  // 获取当前项目目录
31
37
  const curProjectDir = getProjectDir(curWebpackConfig.projectDir);
32
38
  const webpackConfig = {
@@ -46,6 +52,11 @@ module.exports = (_curEnvConfig, _curWebpackConfig) => {
46
52
  * 当webpack试图去加载模块的时候,它默认是查找以 .js 结尾的文件的
47
53
  */
48
54
  resolve: curWebpackConfig.resolve,
55
+ externals: curWebpackConfig.ignoreNodeModules
56
+ ? [nodeExternals({
57
+ allowlist: curWebpackConfig.allowList ? curWebpackConfig.allowList : []
58
+ })].concat(curWebpackConfig.externals)
59
+ : curWebpackConfig.externals,
49
60
  module: {
50
61
  rules: [
51
62
  {
@@ -141,6 +152,46 @@ module.exports = (_curEnvConfig, _curWebpackConfig) => {
141
152
  new VueLoaderPlugin()
142
153
  ]
143
154
  };
155
+ // 优先使用执行环境中的配置
156
+ if (curEnvConfig.ignoreNodeModules !== undefined) {
157
+ const allowList = curEnvConfig.allowList || curWebpackConfig.allowList;
158
+ const externals = curEnvConfig.externals || config.webpack.external || [];
159
+ webpackConfig.externals = curEnvConfig.ignoreNodeModules ? [nodeExternals({
160
+ allowlist: allowList || [],
161
+ })].concat(externals) : externals;
162
+ }
163
+ // 集成构建入口相关的配置(优先级更高)
164
+ if (curEnvConfig.entry) {
165
+ webpackConfig.entry = curEnvConfig.entry; // 会覆盖config.webpack.entry的配置
166
+ }
167
+ // 多页面多模板支持能力
168
+ let entryConfig = webpackConfig.entry || {}; // 获取构建入口配置
169
+ const entryFiles = (entryConfig && Object.keys(entryConfig)) || [];
170
+
171
+ if (
172
+ !webpackConfig.entry ||
173
+ JSON.stringify(webpackConfig.entry) === '{}' ||
174
+ entryFiles.length === 0
175
+ ) {
176
+ // 如果当前构建入口为空,则自动从'./src/pages/'中获取入口文件
177
+ webpackConfig.entry = getJsEntries();
178
+ } else if (webpackConfig.entry && entryFiles.length === 1) {
179
+ /**
180
+ * 只有一个构建入口文件,且项目中不存在此文件,则自动从'./src/pages/'中获取构建入口文件
181
+ */
182
+ const filename = entryFiles[0];
183
+ let entryFilePath = entryConfig[filename];
184
+ // 当前entryFilePath可能是一个地址字符串,也可能是一个存储多个文件地址的数组
185
+ if (isArray(entryFilePath)) {
186
+ // 如果是数组则自动获取最后一个文件地址
187
+ entryFilePath = entryFilePath[entryFilePath.length - 1];
188
+ }
189
+ if (!fs.existsSync(entryFilePath)) {
190
+ // 如果仅有的构建入口文件不存在,则自动从'./src/pages/'中获取入口文件
191
+ const curJsEntries = getJsEntries();
192
+ webpackConfig.entry = curJsEntries ? curJsEntries : webpackConfig.entry;
193
+ }
194
+ }
144
195
  // 是否开启ESLint
145
196
  if (config.settings.enableESLint) {
146
197
  // ts类型
@@ -1,4 +1,3 @@
1
- const fs = require('fs');
2
1
  const webpack = require('webpack');
3
2
  const path = require('path');
4
3
  const merge = require('webpack-merge');
@@ -8,15 +7,13 @@ const utils = require('./loaderUtils');
8
7
  // 引入当前项目配置文件
9
8
  const projectConfig = require('../config/index');
10
9
  const getBaseWebpackConfig = require('./webpack.base.conf');
11
- const getJsEntries = require('../utils/jsEntries');
12
10
  const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
13
- const { isArray } = require('../utils/typeof');
14
11
 
15
12
  module.exports = (akfunConfig) => {
16
13
  let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
17
14
  const curEnvConfig = config.dev || {}; // 当前执行环境配置
18
15
  // 获取webpack基本配置
19
- const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config.webpack);
16
+ const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
20
17
 
21
18
  // 获取页面模板地址
22
19
  let curHtmlTemplate = path.resolve(__dirname, '../initData/template/index.html');
@@ -49,40 +46,6 @@ module.exports = (akfunConfig) => {
49
46
  ]
50
47
  });
51
48
 
52
- // 集成dev配置中的构建入口(优先级高于config.webpack.entry)
53
- if (curEnvConfig.entry) {
54
- webpackDevConfig.entry = curEnvConfig.entry; // 备注:会覆盖config.webpack.entry的配置
55
- }
56
-
57
- // 多页面多模板支持能力
58
- let entryConfig = webpackDevConfig.entry || {}; // 获取构建入口配置
59
- const entryFiles = (entryConfig && Object.keys(entryConfig)) || [];
60
-
61
- if (
62
- !webpackDevConfig.entry ||
63
- JSON.stringify(webpackDevConfig.entry) === '{}' ||
64
- entryFiles.length === 0
65
- ) {
66
- // 如果当前构建入口为空,则自动从'./src/pages/'中获取入口文件
67
- webpackDevConfig.entry = getJsEntries();
68
- } else if (webpackDevConfig.entry && entryFiles.length === 1) {
69
- /**
70
- * 只有一个构建入口文件,且项目中不存在此文件,则自动从'./src/pages/'中获取构建入口文件
71
- */
72
- const filename = entryFiles[0];
73
- let entryFilePath = entryConfig[filename];
74
- // 当前entryFilePath可能是一个地址字符串,也可能是一个存储多个文件地址的数组
75
- if (isArray(entryFilePath)) {
76
- // 如果是数组则自动获取最后一个文件地址
77
- entryFilePath = entryFilePath[entryFilePath.length - 1];
78
- }
79
- if (!fs.existsSync(entryFilePath)) {
80
- // 如果仅有的构建入口文件不存在,则自动从'./src/pages/'中获取入口文件
81
- const curJsEntries = getJsEntries();
82
- webpackDevConfig.entry = curJsEntries ? curJsEntries : webpackDevConfig.entry;
83
- }
84
- }
85
-
86
49
  // 使用用户自定义的多入口配置,生产对应的多页面多模板(优先使用用户的自定义页面模板)
87
50
  const htmlWebpackPluginList = entrys2htmlWebpackPlugin(webpackDevConfig.entry, curHtmlTemplate);
88
51
  htmlWebpackPluginList.forEach((htmlWebpackPlugin) => {
@@ -6,7 +6,6 @@ const CompressionWebpackPlugin = require('compression-webpack-plugin');
6
6
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
7
7
  const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
8
8
  const ProgressBarPlugin = require('progress-bar-webpack-plugin');
9
- const nodeExternals = require('webpack-node-externals');
10
9
 
11
10
  const utils = require('./loaderUtils');
12
11
  // 引入当前项目配置文件
@@ -17,7 +16,7 @@ module.exports = (akfunConfig) => {
17
16
  let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
18
17
  const curEnvConfig = config.build2lib || {}; // 当前执行环境配置
19
18
  // 获取webpack基本配置
20
- const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config.webpack);
19
+ const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
21
20
 
22
21
  const webpackLibConfig = merge(baseWebpackConfig, {
23
22
  mode: curEnvConfig.NODE_ENV, // production 模式,会启动UglifyJsPlugin服务
@@ -36,11 +35,6 @@ module.exports = (akfunConfig) => {
36
35
  })
37
36
  },
38
37
  devtool: curEnvConfig.productionSourceMap ? '#source-map' : false, // '#source-map': 源码,false:压缩代码
39
- externals: config.webpack.ignoreNodeModules
40
- ? [nodeExternals({
41
- allowlist: config.webpack.allowList ? config.webpack.allowList : []
42
- })].concat(config.webpack.externals)
43
- : config.webpack.externals,
44
38
  plugins: [
45
39
  new webpack.DefinePlugin({
46
40
  'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV)
@@ -48,7 +42,7 @@ module.exports = (akfunConfig) => {
48
42
  new MiniCssExtractPlugin({
49
43
  // filename: utils.assetsPath('index.css'),
50
44
  filename: "[name].css",
51
- chunkFilename: "[id].css",
45
+ chunkFilename: "[name].css",
52
46
  ignoreOrder: false
53
47
  }),
54
48
  new OptimizeCSSPlugin({
@@ -78,10 +72,5 @@ module.exports = (akfunConfig) => {
78
72
  webpackLibConfig.plugins.push(new BundleAnalyzerPlugin());
79
73
  }
80
74
 
81
- // 集成构建入口相关的配置
82
- if (curEnvConfig.entry) {
83
- webpackLibConfig.entry = curEnvConfig.entry; // 会覆盖config.webpack.entry的配置
84
- }
85
-
86
75
  return webpackLibConfig;
87
76
  };
@@ -10,14 +10,11 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl
10
10
  const CompressionWebpackPlugin = require('compression-webpack-plugin');
11
11
  const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
12
12
  const ProgressBarPlugin = require('progress-bar-webpack-plugin');
13
- const nodeExternals = require('webpack-node-externals');
14
13
  const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
15
14
 
16
15
  const utils = require('./loaderUtils');
17
16
  const { resolve } = require('../utils/pathUtils'); // 统一路径解析
18
- const getJsEntries = require('../utils/jsEntries');
19
17
  const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
20
- const { isArray } = require('../utils/typeof');
21
18
  // 引入当前项目配置文件
22
19
  const projectConfig = require('../config/index');
23
20
  const getBaseWebpackConfig = require('./webpack.base.conf');
@@ -26,7 +23,7 @@ module.exports = (akfunConfig) => {
26
23
  let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
27
24
  const curEnvConfig = config.build || {}; // 当前执行环境配置
28
25
  // 获取webpack基本配置
29
- const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config.webpack);
26
+ const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig, config);
30
27
  // 获取页面模板地址
31
28
  let curHtmlTemplate = path.resolve(__dirname, '../initData/template/index.html');
32
29
  if (config.webpack.template) {
@@ -55,11 +52,6 @@ module.exports = (akfunConfig) => {
55
52
  environment: 'prod'
56
53
  })
57
54
  },
58
- externals: config.webpack.ignoreNodeModules
59
- ? [nodeExternals({
60
- allowlist: config.webpack.allowList ? config.webpack.allowList : []
61
- })].concat(config.webpack.externals)
62
- : config.webpack.externals,
63
55
  // devtool: '#cheap-module-eval-source-map', // 本地开发环境中的取值
64
56
  devtool: curEnvConfig.productionSourceMap ? '#source-map' : false, // 线上开发环境中的取值
65
57
  optimization: {
@@ -110,41 +102,6 @@ module.exports = (akfunConfig) => {
110
102
  ]
111
103
  });
112
104
 
113
- // 集成build配置中的构建入口
114
- if (curEnvConfig.entry) {
115
- // 会覆盖config.webpack.entry的配置
116
- webpackProdConfig.entry = curEnvConfig.entry;
117
- }
118
-
119
- // 多页面支持能力
120
- let entryConfig = webpackProdConfig.entry || {}; // 获取构建入口配置
121
- const entryFiles = (entryConfig && Object.keys(entryConfig)) || [];
122
-
123
- if (
124
- !webpackProdConfig.entry ||
125
- JSON.stringify(webpackProdConfig.entry) === '{}' ||
126
- entryFiles.length === 0
127
- ) {
128
- // 自动从'./src/pages/'中获取入口文件
129
- webpackProdConfig.entry = getJsEntries();
130
- } else if (webpackProdConfig.entry && entryFiles.length === 1) {
131
- /**
132
- * 只有一个构建入口文件,且项目中不存在此文件,则自动从'./src/pages/'中获取构建入口文件
133
- */
134
- const filename = entryFiles[0];
135
- let entryFilePath = entryConfig[filename];
136
- // 当前entryFilePath可能是一个地址字符串,也可能是一个存储多个文件地址的数组
137
- if (isArray(entryFilePath)) {
138
- // 如果是数组则自动获取最后一个文件地址
139
- entryFilePath = entryFilePath[entryFilePath.length - 1];
140
- }
141
- if (!fs.existsSync(entryFilePath)) {
142
- // 如果仅有的构建入口文件不存在,则自动从'./src/pages/'中获取入口文件
143
- const curJsEntries = getJsEntries();
144
- webpackProdConfig.entry = curJsEntries ? curJsEntries : webpackProdConfig.entry;
145
- }
146
- }
147
-
148
105
  // 使用用户自定义的多入口配置,生产对应的多页面多模板
149
106
  const htmlWebpackPluginList = entrys2htmlWebpackPlugin(webpackProdConfig.entry, curHtmlTemplate);
150
107