akfun 1.5.16 → 1.5.17

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/module/index.js CHANGED
@@ -137,7 +137,7 @@ let argv = yargs
137
137
  .alias('h', 'help');
138
138
  },
139
139
  (argv) => {
140
- mainAction.build();
140
+ mainAction.build('prod');
141
141
  },
142
142
  )
143
143
  .command(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akfun",
3
- "version": "1.5.16",
3
+ "version": "1.5.17",
4
4
  "description": "前端脚手架:支持Vue技术栈和react技术栈",
5
5
  "keywords": [
6
6
  "前端工程",
package/src/build.js CHANGED
@@ -4,10 +4,15 @@ const path = require('path');
4
4
  const chalk = require('chalk');
5
5
  const webpack = require('webpack');
6
6
  const checkVersion = require('./check-versions');
7
- const config = require('./config/index'); // 引入当前项目配置文件
7
+ const projectConfig = require('./config/index'); // 引入当前项目配置文件
8
+ const deepMergeConfig = require('./utils/deepMergeConfig');
8
9
 
9
10
  // 构建脚本:一般用于构建生产环境的代码
10
- module.exports = function (BuildType) {
11
+ module.exports = function (BuildType, akfunConfig) {
12
+ let config = projectConfig; // 默认使用执行命令目录下的配置数据
13
+ if (akfunConfig) {
14
+ config = deepMergeConfig(defaultConfig, akfunConfig);
15
+ }
11
16
  // 检查当前npm版本号是否匹配
12
17
  checkVersion();
13
18
  const spinner = ora('[akfun]开启AKFun构建能力...').start();
@@ -16,10 +21,10 @@ module.exports = function (BuildType) {
16
21
  // 根据BuildType判断是否引用专用于第三方功能包的webpack配置
17
22
  if (BuildType && BuildType === 'lib') {
18
23
  spinner.start('[akfun]开始构建第三方功能包...');
19
- webpackConfig = require('./webpack/webpack.library.conf')();
24
+ webpackConfig = require('./webpack/webpack.library.conf')(config);
20
25
  } else {
21
26
  spinner.start('[akfun]开始构建生产环境的代码...');
22
- webpackConfig = require('./webpack/webpack.prod.conf')();
27
+ webpackConfig = require('./webpack/webpack.prod.conf')(config);
23
28
  }
24
29
 
25
30
  /**
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+ // 统一路径解析:
3
+ const { resolve } = require('../utils/pathUtils');
4
+
5
+ /**
6
+ * akfun脚手架赋予当前项目的默认配置
7
+ */
8
+ const defaultAKFunConfig = {
9
+ settings: {
10
+ enableESLint: false, // 是否开启ESLint,默认开启ESLint检测代码格式
11
+ enableESLintFix: false, // 是否ESLint自动修正代码格式
12
+ enableStyleLint: false, // 是否开启StyleLint,默认开启ESLint检测代码格式
13
+ enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
14
+ },
15
+ webpack: {
16
+ resolve: {
17
+ // webpack的resolve配置
18
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.json'], // 用于配置webpack在尝试过程中用到的后缀列表
19
+ alias: {
20
+ '@': resolve('src'),
21
+ $components: resolve('src/components'),
22
+ $pages: resolve('src/pages'),
23
+ $plugins: resolve('src/plugins'),
24
+ $utils: resolve('src/utils')
25
+ }
26
+ },
27
+ createDeclaration: false, // 打包时是否创建ts声明文件
28
+ ignoreNodeModules: false, // 打包时是否忽略 node_modules
29
+ externals: [], // 从输出的 bundle 中排除依赖
30
+ sassResources: []
31
+ },
32
+ envParams: {
33
+ // 项目系统环境变量
34
+ common: {
35
+ // 通用参数
36
+ '#version#': '20200810.1'
37
+ },
38
+ local: {
39
+ // 本地开发环境
40
+ '#dataApiBase#': 'http://localhost:1024', // 数据接口根地址
41
+ '#assetsPublicPath#': 'http://localhost:1024', // 静态资源根地址
42
+ '#routeBasePath#': '/' // 路由根地址
43
+ },
44
+ online: {
45
+ // 线上正式环境配置参数
46
+ '#dataApiBase#': '/', // 数据接口根地址 "//xxx.cn/"格式
47
+ '#assetsPublicPath#': '', // 静态资源根地址 "//xxx.cn/_spa/projectName"格式
48
+ '#routeBasePath#': '/' // 路由根地址 "/_spa/projectName/"格式
49
+ }
50
+ },
51
+ dev: {
52
+ // 用于开启本地调试模式的相关配置信息
53
+ NODE_ENV: 'development',
54
+ port: 80,
55
+ autoOpenBrowser: true,
56
+ assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
57
+ assetsSubDirectory: '',
58
+ hostname: 'localhost',
59
+ proxyTable: {},
60
+ /** CSS Sourcemaps off by default because relative paths are "buggy"
61
+ * with this option, according to the CSS-Loader README
62
+ * (https://github.com/webpack/css-loader#sourcemaps)
63
+ * In our experience, they generally work as expected,
64
+ * just be aware of this issue when enabling this option.
65
+ */
66
+ cssSourceMap: false
67
+ },
68
+ build: {
69
+ // 用于构建生产环境代码的相关配置信息
70
+ NODE_ENV: 'production', // production 模式,会启动UglifyJsPlugin服务
71
+ assetsRoot: resolve('dist'), // 编译完成的文件存放路径
72
+ assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
73
+ assetsSubDirectory: '', // 资源引用二级路径
74
+ productionSourceMap: false,
75
+ // Gzip off by default as many popular public hosts such as
76
+ // Surge or Netlify already gzip all public assets for you.
77
+ // Before setting to `true`, make sure to:
78
+ // npm install --save-dev compression-webpack-plugin
79
+ productionGzip: false,
80
+ productionGzipExtensions: ['js', 'css', 'json'],
81
+ // Run the build command with an extra argument to
82
+ // View the bundle analyzer report after build finishes:
83
+ // `npm run build --report`
84
+ // Set to `true` or `false` to always turn it on or off
85
+ bundleAnalyzerReport: false
86
+ },
87
+ build2lib: {
88
+ // 用于构建第三方功能包的配置文件
89
+ NODE_ENV: 'production',
90
+ libraryName: '', // 构建第三方功能包时最后导出的引用变量名
91
+ assetsRoot: resolve('dist'), // 编译完成的文件存放路径
92
+ assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
93
+ assetsSubDirectory: '', // 资源引用二级路径
94
+ productionSourceMap: false,
95
+ productionGzip: false,
96
+ productionGzipExtensions: ['js', 'css', 'json'],
97
+ bundleAnalyzerReport: false
98
+ }
99
+ };
100
+
101
+ // 备注:数组类型则直接覆盖
102
+ module.exports = defaultAKFunConfig;
@@ -1,110 +1,16 @@
1
1
  'use strict';
2
- const deepMerge = require('deepmerge');
3
2
  // 统一路径解析:
4
3
  const { resolve } = require('../utils/pathUtils');
4
+ const defaultAKFunConfig = require('./default.config');
5
5
  const getConfigObj = require('../utils/getConfigObj');
6
+ const deepMergeConfig = require('../utils/deepMergeConfig');
6
7
 
7
8
  /** akfun脚手架赋予当前项目的默认配置
8
9
  * 备注:项目根目录的akfun.config.js的配置内容优先级高于defultAKFunConfig
9
10
  */
10
- const defaultAKFunConfig = {
11
- settings: {
12
- enableESLint: false, // 是否开启ESLint,默认开启ESLint检测代码格式
13
- enableESLintFix: false, // 是否ESLint自动修正代码格式
14
- enableStyleLint: false, // 是否开启StyleLint,默认开启ESLint检测代码格式
15
- enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
16
- },
17
- webpack: {
18
- resolve: {
19
- // webpack的resolve配置
20
- extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.json'], // 用于配置webpack在尝试过程中用到的后缀列表
21
- alias: {
22
- '@': resolve('src'),
23
- $components: resolve('src/components'),
24
- $pages: resolve('src/pages'),
25
- $plugins: resolve('src/plugins'),
26
- $utils: resolve('src/utils')
27
- }
28
- },
29
- createDeclaration: false, // 打包时是否创建ts声明文件
30
- ignoreNodeModules: false, // 打包时是否忽略 node_modules
31
- externals: [], // 从输出的 bundle 中排除依赖
32
- sassResources: []
33
- },
34
- envParams: {
35
- // 项目系统环境变量
36
- common: {
37
- // 通用参数
38
- '#version#': '20200810.1'
39
- },
40
- local: {
41
- // 本地开发环境
42
- '#dataApiBase#': 'http://localhost:1024', // 数据接口根地址
43
- '#assetsPublicPath#': 'http://localhost:1024', // 静态资源根地址
44
- '#routeBasePath#': '/' // 路由根地址
45
- },
46
- online: {
47
- // 线上正式环境配置参数
48
- '#dataApiBase#': '/', // 数据接口根地址 "//xxx.cn/"格式
49
- '#assetsPublicPath#': '', // 静态资源根地址 "//xxx.cn/_spa/projectName"格式
50
- '#routeBasePath#': '/' // 路由根地址 "/_spa/projectName/"格式
51
- }
52
- },
53
- dev: {
54
- // 用于开启本地调试模式的相关配置信息
55
- NODE_ENV: 'development',
56
- port: 80,
57
- autoOpenBrowser: true,
58
- assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
59
- assetsSubDirectory: '',
60
- hostname: 'localhost',
61
- proxyTable: {},
62
- /** CSS Sourcemaps off by default because relative paths are "buggy"
63
- * with this option, according to the CSS-Loader README
64
- * (https://github.com/webpack/css-loader#sourcemaps)
65
- * In our experience, they generally work as expected,
66
- * just be aware of this issue when enabling this option.
67
- */
68
- cssSourceMap: false
69
- },
70
- build: {
71
- // 用于构建生产环境代码的相关配置信息
72
- NODE_ENV: 'production', // production 模式,会启动UglifyJsPlugin服务
73
- assetsRoot: resolve('dist'), // 编译完成的文件存放路径
74
- assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
75
- assetsSubDirectory: '', // 资源引用二级路径
76
- productionSourceMap: false,
77
- // Gzip off by default as many popular public hosts such as
78
- // Surge or Netlify already gzip all public assets for you.
79
- // Before setting to `true`, make sure to:
80
- // npm install --save-dev compression-webpack-plugin
81
- productionGzip: false,
82
- productionGzipExtensions: ['js', 'css', 'json'],
83
- // Run the build command with an extra argument to
84
- // View the bundle analyzer report after build finishes:
85
- // `npm run build --report`
86
- // Set to `true` or `false` to always turn it on or off
87
- bundleAnalyzerReport: false
88
- },
89
- build2lib: {
90
- // 用于构建第三方功能包的配置文件
91
- NODE_ENV: 'production',
92
- libraryName: '', // 构建第三方功能包时最后导出的引用变量名
93
- assetsRoot: resolve('dist'), // 编译完成的文件存放路径
94
- assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
95
- assetsSubDirectory: '', // 资源引用二级路径
96
- productionSourceMap: false,
97
- productionGzip: false,
98
- productionGzipExtensions: ['js', 'css', 'json'],
99
- bundleAnalyzerReport: false
100
- }
101
- };
102
11
 
103
12
  // 从项目根目录获取当前项目的配置文件
104
13
  const curProjectConfig = getConfigObj(resolve('akfun.config.js'));
105
14
 
106
- // module.exports = Object.assign(defaultAKFunConfig, curProjectConfig);
107
-
108
- const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
109
15
  // 备注:数组类型则直接覆盖
110
- module.exports = deepMerge(defaultAKFunConfig, curProjectConfig, { arrayMerge: overwriteMerge });
16
+ module.exports = deepMergeConfig(defaultAKFunConfig, curProjectConfig);
package/src/dev-server.js CHANGED
@@ -7,11 +7,17 @@ const checkVersion = require('./check-versions');
7
7
  const { createProxyMiddleware } = require('http-proxy-middleware');
8
8
  const { resolve } = require('./utils/pathUtils');
9
9
  // 引入当前项目配置文件
10
- const config = require('./config/index');
10
+ const projectConfig = require('./config/index');
11
+ const defaultConfig = require('./config/default.config');
11
12
  const getDevWebpackConfig = require('./webpack/webpack.dev.conf');
13
+ const deepMergeConfig = require('./utils/deepMergeConfig');
12
14
 
13
15
  // 构建脚本:一般用于构建开发环境的代码(包含热更新、接口代理等功能)
14
- module.exports = function () {
16
+ module.exports = function (akfunConfig) {
17
+ let config = projectConfig; // 默认使用执行命令目录下的配置数据
18
+ if (akfunConfig) {
19
+ config = deepMergeConfig(defaultConfig, akfunConfig);
20
+ }
15
21
  // 检查当前npm版本号是否匹配
16
22
  checkVersion();
17
23
  const spinner = ora('[akfun]开启调试模式...').start();
@@ -35,7 +41,7 @@ module.exports = function () {
35
41
  // 使用 express 启动一个服务
36
42
  const app = express();
37
43
  // 获取开发环境的webpack基本配置
38
- const webpackConfig = getDevWebpackConfig();
44
+ const webpackConfig = getDevWebpackConfig(config);
39
45
  const compiler = webpack(webpackConfig); // 启动 webpack 进行编译
40
46
 
41
47
  // 启动 webpack-dev-middleware,将编译后的文件暂存到内存中
@@ -0,0 +1,9 @@
1
+ const deepMerge = require('deepmerge');
2
+
3
+ const deepMergeConfig = function (defaultConfig, curConfig) {
4
+ const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
5
+
6
+ return deepMerge(defaultConfig, curConfig, { arrayMerge: overwriteMerge });
7
+ };
8
+
9
+ module.exports = deepMergeConfig;
@@ -6,13 +6,14 @@ const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
6
6
  const ProgressBarPlugin = require('progress-bar-webpack-plugin');
7
7
  const utils = require('./loaderUtils');
8
8
  // 引入当前项目配置文件
9
- const config = require('../config/index');
9
+ const projectConfig = require('../config/index');
10
10
  const getBaseWebpackConfig = require('./webpack.base.conf');
11
11
  const getJsEntries = require('../utils/jsEntries');
12
12
  const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
13
13
  const { isArray } = require('../utils/typeof');
14
14
 
15
- module.exports = () => {
15
+ module.exports = (akfunConfig) => {
16
+ let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
16
17
  const curEnvConfig = config.dev || {}; // 当前执行环境配置
17
18
  // 获取webpack基本配置
18
19
  const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig);
@@ -10,10 +10,11 @@ const nodeExternals = require('webpack-node-externals');
10
10
 
11
11
  const utils = require('./loaderUtils');
12
12
  // 引入当前项目配置文件
13
- const config = require('../config/index');
13
+ const projectConfig = require('../config/index');
14
14
  const getBaseWebpackConfig = require('./webpack.base.conf');
15
15
 
16
- module.exports = () => {
16
+ module.exports = (akfunConfig) => {
17
+ let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
17
18
  const curEnvConfig = config.build2lib || {}; // 当前执行环境配置
18
19
  // 获取webpack基本配置
19
20
  const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig);
@@ -18,10 +18,11 @@ const getJsEntries = require('../utils/jsEntries');
18
18
  const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
19
19
  const { isArray } = require('../utils/typeof');
20
20
  // 引入当前项目配置文件
21
- const config = require('../config/index');
21
+ const projectConfig = require('../config/index');
22
22
  const getBaseWebpackConfig = require('./webpack.base.conf');
23
23
 
24
- module.exports = () => {
24
+ module.exports = (akfunConfig) => {
25
+ let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
25
26
  const curEnvConfig = config.build || {}; // 当前执行环境配置
26
27
  // 获取webpack基本配置
27
28
  const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig);