akfun 2.0.1 → 2.0.6

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": "2.0.1",
3
+ "version": "2.0.6",
4
4
  "description": "前端脚手架:支持Vue技术栈和react技术栈",
5
5
  "keywords": [
6
6
  "前端工程",
package/src/dev-server.js CHANGED
@@ -11,7 +11,7 @@ const projectConfig = require('./config/index');
11
11
  const defaultConfig = require('./config/default.config');
12
12
  const getDevWebpackConfig = require('./webpack/webpack.dev.conf');
13
13
  const deepMergeConfig = require('./utils/deepMergeConfig');
14
- const {curConsoleTag } = require("./utils/akfunParams");
14
+ const { curConsoleTag } = require('./utils/akfunParams');
15
15
 
16
16
  // 构建脚本:一般用于构建开发环境的代码(包含热更新、接口代理等功能)
17
17
  module.exports = function (akfunConfig, _consoleTag) {
@@ -112,11 +112,23 @@ module.exports = function (akfunConfig, _consoleTag) {
112
112
  }
113
113
  process.env.PORT = port;
114
114
  const uri = `http://${config.dev.hostname}:${port}`;
115
+
115
116
  console.log(`> Listening at ${uri}\n`);
116
117
  // 如果是开发环境,自动打开浏览器并跳到项目首页
117
- if (autoOpenBrowser && process.NODE_ENV === 'development') {
118
+ if (autoOpenBrowser) {
118
119
  spinner.succeed(`${consoleTag}调试模式已开启!`);
119
- opn(uri);
120
+ // 打印当前环境中的首个html和css地址
121
+ const projPath = `${uri}${webpackConfig.output.publicPath}`;
122
+ let entryConfig = webpackConfig.entry || {}; // 获取构建入口配置
123
+ const entryFiles = (entryConfig && Object.keys(entryConfig)) || [];
124
+ if (entryFiles.length > 0) {
125
+ // 获取第一个入口文件
126
+ const filename = entryFiles[0];
127
+ console.info(
128
+ `当前运行脚本:\n ${projPath}${filename}.html\n当前运行样式[可能不存在]:\n${projPath}${filename}.css`
129
+ );
130
+ opn(`${projPath}${filename}.html`);
131
+ }
120
132
  }
121
133
  server = app.listen(port);
122
134
  _resolve();
@@ -15,7 +15,7 @@ const catchVuePages = require('../utils/catchVuePages'); // 用于获取当前
15
15
  // 引入当前项目配置文件
16
16
  const projectConfig = require('../config/index');
17
17
  const babelConfig = require('../config/babel.config'); // Babel的配置文件
18
- const {buildBanner} = require("../utils/akfunParams");
18
+ const { buildBanner } = require('../utils/akfunParams');
19
19
  const getJsEntries = require('../utils/jsEntries');
20
20
  const { isArray } = require('../utils/typeof');
21
21
 
@@ -38,6 +38,11 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
38
38
  // 获取当前项目目录
39
39
  const curProjectDir = getProjectDir(curWebpackConfig.projectDir);
40
40
  const webpackConfig = {
41
+ stats: {
42
+ // cachedModules: false,
43
+ // providedExports: true,
44
+ // warnings: false
45
+ },
41
46
  entry: curWebpackConfig.entry,
42
47
  // target: 'web', // <=== 默认为 'web',可省略
43
48
  target: ['web', 'es5'], // 使用共同的特性子集
@@ -58,9 +63,12 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
58
63
  */
59
64
  resolve: curWebpackConfig.resolve,
60
65
  externals: curWebpackConfig.ignoreNodeModules
61
- ? [nodeExternals({
62
- allowlist: curWebpackConfig.allowList ? curWebpackConfig.allowList : []
63
- })].concat(curWebpackConfig.externals)
66
+ ? [
67
+ nodeExternals({
68
+ importType: 'commonjs',
69
+ allowlist: curWebpackConfig.allowList ? curWebpackConfig.allowList : []
70
+ })
71
+ ].concat(curWebpackConfig.externals)
64
72
  : curWebpackConfig.externals,
65
73
  module: {
66
74
  rules: [
@@ -166,9 +174,14 @@ module.exports = (_curEnvConfig, _akfunConfig) => {
166
174
  if (curEnvConfig.ignoreNodeModules !== undefined) {
167
175
  const allowList = curEnvConfig.allowList || curWebpackConfig.allowList;
168
176
  const externals = curEnvConfig.externals || config.webpack.external || [];
169
- webpackConfig.externals = curEnvConfig.ignoreNodeModules ? [nodeExternals({
170
- allowlist: allowList || [],
171
- })].concat(externals) : externals;
177
+ webpackConfig.externals = curEnvConfig.ignoreNodeModules
178
+ ? [
179
+ nodeExternals({
180
+ importType: 'commonjs',
181
+ allowlist: allowList || []
182
+ })
183
+ ].concat(externals)
184
+ : externals;
172
185
  }
173
186
  // 集成构建入口相关的配置(优先级更高)
174
187
  if (curEnvConfig.entry) {
@@ -6,6 +6,8 @@ const utils = require('./loaderUtils');
6
6
  const projectConfig = require('../config/index');
7
7
  const getBaseWebpackConfig = require('./webpack.base.conf');
8
8
  const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
9
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
10
+ const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
9
11
 
10
12
  module.exports = (akfunConfig) => {
11
13
  let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
@@ -27,35 +29,29 @@ module.exports = (akfunConfig) => {
27
29
  module: {
28
30
  rules: utils.styleLoaders({
29
31
  sourceMap: curEnvConfig.cssSourceMap,
30
- environment: 'dev'
32
+ environment: 'prod' // 'dev': 不会将css单独提取出来
31
33
  })
32
34
  },
33
35
  // devtool: '#cheap-module-eval-source-map', // 本地开发环境中的取值
34
36
  devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'eval-source-map' : 'eval', // 开发环境
35
37
  optimization: {
36
38
  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
- }
39
+ emitOnErrors: true
55
40
  },
56
41
  plugins: [
57
42
  // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
58
43
  new webpack.HotModuleReplacementPlugin(),
44
+ new MiniCssExtractPlugin({
45
+ // filename: utils.assetsPath('index.css'),
46
+ filename: '[name].css',
47
+ chunkFilename: '[name].css',
48
+ ignoreOrder: false
49
+ }),
50
+ new OptimizeCSSPlugin({
51
+ cssProcessorOptions: {
52
+ safe: true
53
+ }
54
+ })
59
55
  ]
60
56
  });
61
57
 
@@ -68,7 +64,7 @@ module.exports = (akfunConfig) => {
68
64
  // 开启热更新能力
69
65
  const devClientPath = path.resolve(__dirname, '../dev-client'); // 从akfun中获取
70
66
  // add hot-reload related code to entry chunks
71
- if (webpackDevConfig.entry) {
67
+ if (!curEnvConfig.closeHotReload && webpackDevConfig.entry) {
72
68
  Object.keys(webpackDevConfig.entry).forEach((name) => {
73
69
  webpackDevConfig.entry[name] = [devClientPath].concat(webpackDevConfig.entry[name]);
74
70
  });
@@ -19,14 +19,14 @@ module.exports = (akfunConfig) => {
19
19
  mode: curEnvConfig.NODE_ENV, // production 模式,会启动UglifyJsPlugin服务
20
20
  output: {
21
21
  path: curEnvConfig.assetsRoot, // 输出文件的存放在本地的目录
22
- filename: 'index.umd.js',
22
+ filename: '[name].umd.js',
23
23
  publicPath: '',
24
24
  library: {
25
25
  type: 'umd', // 定义打包方式Universal Module Definition,同时支持在CommonJS、AMD和全局变量使用
26
- name: curEnvConfig.libraryName,
26
+ name: curEnvConfig.libraryName
27
27
  },
28
28
  // 指定类库名,主要用于直接引用的方式(比如使用script 标签)
29
- globalObject: 'this', // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
29
+ globalObject: 'this' // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
30
30
  },
31
31
  module: {
32
32
  rules: utils.styleLoaders({
@@ -34,7 +34,7 @@ module.exports = (akfunConfig) => {
34
34
  environment: 'prod'
35
35
  })
36
36
  },
37
- devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'source-map' : false, // 线上生成环境
37
+ devtool: curEnvConfig.productionSourceMap ? curEnvConfig.devtool || 'source-map' : false, // 线上生成环境
38
38
  optimization: {
39
39
  /**
40
40
  * named 对调试更友好的可读的 id。
@@ -46,15 +46,15 @@ module.exports = (akfunConfig) => {
46
46
  plugins: [
47
47
  new MiniCssExtractPlugin({
48
48
  // filename: utils.assetsPath('index.css'),
49
- filename: "[name].css",
50
- chunkFilename: "[name].css",
49
+ filename: '[name].css',
50
+ chunkFilename: '[name].css',
51
51
  ignoreOrder: false
52
52
  }),
53
53
  new OptimizeCSSPlugin({
54
54
  cssProcessorOptions: {
55
55
  safe: true
56
56
  }
57
- }),
57
+ })
58
58
  ]
59
59
  });
60
60
 
@@ -55,7 +55,8 @@ module.exports = (akfunConfig) => {
55
55
  emitOnErrors: true,
56
56
  splitChunks: {
57
57
  cacheGroups: {
58
- defaultVendors: { // 4.0: vendors
58
+ defaultVendors: {
59
+ // 4.0: vendors
59
60
  test: /node_modules\/(.*)/,
60
61
  name: 'vendor',
61
62
  chunks: 'initial',
@@ -90,7 +91,7 @@ module.exports = (akfunConfig) => {
90
91
  cssProcessorOptions: {
91
92
  safe: true
92
93
  }
93
- }),
94
+ })
94
95
  ]
95
96
  });
96
97
 
@@ -128,7 +129,7 @@ module.exports = (akfunConfig) => {
128
129
  })
129
130
  );
130
131
  }
131
-
132
+
132
133
  // 是否开启
133
134
  if (curEnvConfig.openMonacoWebpackPlugin) {
134
135
  webpackProdConfig.plugins.push(new MonacoWebpackPlugin());