akfun 1.6.6 → 1.6.10

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.6",
3
+ "version": "1.6.10",
4
4
  "description": "前端脚手架:支持Vue技术栈和react技术栈",
5
5
  "keywords": [
6
6
  "前端工程",
package/src/build2esm.js CHANGED
@@ -34,8 +34,8 @@ module.exports = function (fileName, akfunConfig, _consoleTag) {
34
34
  // 参数中的config配置优先级最高
35
35
  config = deepMergeConfig(defaultConfig, akfunConfig);
36
36
  }
37
- const spinner = ora(`${consoleTag}开启esm lib库的构建能力...`).start();
38
- const curRollupConfig = rollupConfig(fileName); // 默认配置
37
+ const spinner = ora(`${consoleTag}开启esm模块构建能力...`).start();
38
+ const curRollupConfig = rollupConfig(fileName, config); // 默认配置
39
39
  const build2esm = config.build2esm; // 用户的项目配置
40
40
  if (build2esm && build2esm.input) {
41
41
  curRollupConfig.input = build2esm.input;
@@ -3,6 +3,7 @@ const webpack = require('webpack');
3
3
  // const tsImportPluginFactory = require('ts-import-plugin'); // 按需加载lib库组件代码
4
4
  const StyleLintPlugin = require('stylelint-webpack-plugin');
5
5
  const VueLoaderPlugin = require('vue-loader/lib/plugin');
6
+ const nodeExternals = require('webpack-node-externals');
6
7
  const utils = require('./loaderUtils');
7
8
  const vueLoaderConfig = require('./vue-loader.conf');
8
9
  const { resolve, resolveToCurrentRoot } = require('../utils/pathUtils');
@@ -12,6 +13,9 @@ const catchVuePages = require('../utils/catchVuePages'); // 用于获取当前
12
13
  const config = require('../config/index');
13
14
  const babelConfig = require('../config/babel.config'); // Babel的配置文件
14
15
  const {buildBanner} = require("../utils/akfunParams");
16
+ const getJsEntries = require('../utils/jsEntries');
17
+ const { isArray } = require('../utils/typeof');
18
+ const fs = require('fs');
15
19
 
16
20
 
17
21
  // 生成构建头部信息
@@ -46,6 +50,11 @@ module.exports = (_curEnvConfig, _curWebpackConfig) => {
46
50
  * 当webpack试图去加载模块的时候,它默认是查找以 .js 结尾的文件的
47
51
  */
48
52
  resolve: curWebpackConfig.resolve,
53
+ externals: config.webpack.ignoreNodeModules
54
+ ? [nodeExternals({
55
+ allowlist: config.webpack.allowList ? config.webpack.allowList : []
56
+ })].concat(config.webpack.externals)
57
+ : config.webpack.externals,
49
58
  module: {
50
59
  rules: [
51
60
  {
@@ -141,6 +150,45 @@ module.exports = (_curEnvConfig, _curWebpackConfig) => {
141
150
  new VueLoaderPlugin()
142
151
  ]
143
152
  };
153
+ // 优先使用执行环境中的配置
154
+ if (curEnvConfig.ignoreNodeModules) {
155
+ const allowList = curEnvConfig.allowList || config.webpack.allowList;
156
+ webpackConfig.externals = [nodeExternals({
157
+ allowlist: allowList || [],
158
+ })].concat(curEnvConfig.externals || config.webpack.externals);
159
+ }
160
+ // 集成构建入口相关的配置(优先级更高)
161
+ if (curEnvConfig.entry) {
162
+ webpackConfig.entry = curEnvConfig.entry; // 会覆盖config.webpack.entry的配置
163
+ }
164
+ // 多页面多模板支持能力
165
+ let entryConfig = webpackConfig.entry || {}; // 获取构建入口配置
166
+ const entryFiles = (entryConfig && Object.keys(entryConfig)) || [];
167
+
168
+ if (
169
+ !webpackConfig.entry ||
170
+ JSON.stringify(webpackConfig.entry) === '{}' ||
171
+ entryFiles.length === 0
172
+ ) {
173
+ // 如果当前构建入口为空,则自动从'./src/pages/'中获取入口文件
174
+ webpackConfig.entry = getJsEntries();
175
+ } else if (webpackConfig.entry && entryFiles.length === 1) {
176
+ /**
177
+ * 只有一个构建入口文件,且项目中不存在此文件,则自动从'./src/pages/'中获取构建入口文件
178
+ */
179
+ const filename = entryFiles[0];
180
+ let entryFilePath = entryConfig[filename];
181
+ // 当前entryFilePath可能是一个地址字符串,也可能是一个存储多个文件地址的数组
182
+ if (isArray(entryFilePath)) {
183
+ // 如果是数组则自动获取最后一个文件地址
184
+ entryFilePath = entryFilePath[entryFilePath.length - 1];
185
+ }
186
+ if (!fs.existsSync(entryFilePath)) {
187
+ // 如果仅有的构建入口文件不存在,则自动从'./src/pages/'中获取入口文件
188
+ const curJsEntries = getJsEntries();
189
+ webpackConfig.entry = curJsEntries ? curJsEntries : webpackConfig.entry;
190
+ }
191
+ }
144
192
  // 是否开启ESLint
145
193
  if (config.settings.enableESLint) {
146
194
  // 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,9 +7,7 @@ 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; // 默认使用执行命令目录下的配置数据
@@ -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
  // 引入当前项目配置文件
@@ -36,9 +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()].concat(config.webpack.externals)
41
- : config.webpack.externals,
42
38
  plugins: [
43
39
  new webpack.DefinePlugin({
44
40
  'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV)
@@ -46,7 +42,7 @@ module.exports = (akfunConfig) => {
46
42
  new MiniCssExtractPlugin({
47
43
  // filename: utils.assetsPath('index.css'),
48
44
  filename: "[name].css",
49
- chunkFilename: "[id].css",
45
+ chunkFilename: "[name].css",
50
46
  ignoreOrder: false
51
47
  }),
52
48
  new OptimizeCSSPlugin({
@@ -76,10 +72,5 @@ module.exports = (akfunConfig) => {
76
72
  webpackLibConfig.plugins.push(new BundleAnalyzerPlugin());
77
73
  }
78
74
 
79
- // 集成构建入口相关的配置
80
- if (curEnvConfig.entry) {
81
- webpackLibConfig.entry = curEnvConfig.entry; // 会覆盖config.webpack.entry的配置
82
- }
83
-
84
75
  return webpackLibConfig;
85
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');
@@ -55,9 +52,6 @@ module.exports = (akfunConfig) => {
55
52
  environment: 'prod'
56
53
  })
57
54
  },
58
- externals: config.webpack.ignoreNodeModules
59
- ? [nodeExternals()].concat(config.webpack.externals)
60
- : config.webpack.externals,
61
55
  // devtool: '#cheap-module-eval-source-map', // 本地开发环境中的取值
62
56
  devtool: curEnvConfig.productionSourceMap ? '#source-map' : false, // 线上开发环境中的取值
63
57
  optimization: {
@@ -108,41 +102,6 @@ module.exports = (akfunConfig) => {
108
102
  ]
109
103
  });
110
104
 
111
- // 集成build配置中的构建入口
112
- if (curEnvConfig.entry) {
113
- // 会覆盖config.webpack.entry的配置
114
- webpackProdConfig.entry = curEnvConfig.entry;
115
- }
116
-
117
- // 多页面支持能力
118
- let entryConfig = webpackProdConfig.entry || {}; // 获取构建入口配置
119
- const entryFiles = (entryConfig && Object.keys(entryConfig)) || [];
120
-
121
- if (
122
- !webpackProdConfig.entry ||
123
- JSON.stringify(webpackProdConfig.entry) === '{}' ||
124
- entryFiles.length === 0
125
- ) {
126
- // 自动从'./src/pages/'中获取入口文件
127
- webpackProdConfig.entry = getJsEntries();
128
- } else if (webpackProdConfig.entry && entryFiles.length === 1) {
129
- /**
130
- * 只有一个构建入口文件,且项目中不存在此文件,则自动从'./src/pages/'中获取构建入口文件
131
- */
132
- const filename = entryFiles[0];
133
- let entryFilePath = entryConfig[filename];
134
- // 当前entryFilePath可能是一个地址字符串,也可能是一个存储多个文件地址的数组
135
- if (isArray(entryFilePath)) {
136
- // 如果是数组则自动获取最后一个文件地址
137
- entryFilePath = entryFilePath[entryFilePath.length - 1];
138
- }
139
- if (!fs.existsSync(entryFilePath)) {
140
- // 如果仅有的构建入口文件不存在,则自动从'./src/pages/'中获取入口文件
141
- const curJsEntries = getJsEntries();
142
- webpackProdConfig.entry = curJsEntries ? curJsEntries : webpackProdConfig.entry;
143
- }
144
- }
145
-
146
105
  // 使用用户自定义的多入口配置,生产对应的多页面多模板
147
106
  const htmlWebpackPluginList = entrys2htmlWebpackPlugin(webpackProdConfig.entry, curHtmlTemplate);
148
107