akfun 1.5.16 → 1.6.0
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 +4 -4
- package/module/inspect.js +5 -5
- package/module/main.js +13 -0
- package/package.json +5 -4
- package/src/build.js +9 -4
- package/src/config/default.config.js +101 -0
- package/src/config/index.js +3 -98
- package/src/dev-server.js +9 -3
- package/src/initData/config/akfun.config.js +3 -1
- package/src/utils/deepMergeConfig.js +9 -0
- package/src/utils/getCurWebpackConfig.js +5 -5
- package/src/webpack/webpack.dev.conf.js +3 -2
- package/src/webpack/webpack.library.conf.js +6 -3
- package/src/webpack/webpack.prod.conf.js +9 -2
package/module/index.js
CHANGED
|
@@ -129,7 +129,7 @@ let argv = yargs
|
|
|
129
129
|
)
|
|
130
130
|
.command(
|
|
131
131
|
'build',
|
|
132
|
-
'
|
|
132
|
+
'构建生产环境代码',
|
|
133
133
|
(yargs) => {
|
|
134
134
|
yargs
|
|
135
135
|
.reset()
|
|
@@ -137,12 +137,12 @@ 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(
|
|
144
144
|
'build2lib',
|
|
145
|
-
'
|
|
145
|
+
'构建lib库',
|
|
146
146
|
(yargs) => {
|
|
147
147
|
yargs
|
|
148
148
|
.reset()
|
|
@@ -155,7 +155,7 @@ let argv = yargs
|
|
|
155
155
|
)
|
|
156
156
|
.command(
|
|
157
157
|
'build2esm',
|
|
158
|
-
'构建esm
|
|
158
|
+
'构建esm模块',
|
|
159
159
|
(yargs) => {
|
|
160
160
|
yargs
|
|
161
161
|
.reset()
|
package/module/inspect.js
CHANGED
|
@@ -4,7 +4,7 @@ const fs = require('fs');
|
|
|
4
4
|
const getCurWebpackConfig = require('../src/utils/getCurWebpackConfig.js'); // 用于获取当前webpack配置的方法
|
|
5
5
|
|
|
6
6
|
// 根据当前配置文件内容创建指定名称的文件
|
|
7
|
-
const createConfigJs = function (
|
|
7
|
+
const createConfigJs = function (fileName, fileCont) {
|
|
8
8
|
let filePath = path.resolve(process.cwd(), fileName);
|
|
9
9
|
|
|
10
10
|
fs.writeFile(filePath, JSON.stringify(fileCont, null, 2), (err) => {
|
|
@@ -21,18 +21,18 @@ module.exports = (type) => {
|
|
|
21
21
|
const spinner = ora( '[akfun]正在获取当前环境的配置数据...').start();
|
|
22
22
|
if (type === 'dev') {
|
|
23
23
|
const devConfig = getCurWebpackConfig(type);
|
|
24
|
-
createConfigJs(
|
|
24
|
+
createConfigJs('current-akfun-dev-config.js', devConfig);
|
|
25
25
|
spinner.succeed( '[akfun]当前配置数据已输出至akfun-dev-config.js中!');
|
|
26
26
|
} else if (type === 'lib') {
|
|
27
27
|
const libraryConfig = getCurWebpackConfig(type);
|
|
28
|
-
createConfigJs(
|
|
28
|
+
createConfigJs('current-akfun-build2lib-config.js', libraryConfig);
|
|
29
29
|
spinner.succeed( '[akfun]当前配置数据已输出至akfun-build2lib-config.js中!');
|
|
30
30
|
} else if (type === 'build') {
|
|
31
31
|
const prodConfig = getCurWebpackConfig(type);
|
|
32
32
|
// 默认输出生产环境的配置文件
|
|
33
|
-
createConfigJs(
|
|
33
|
+
createConfigJs('current-akfun-build-config.js', prodConfig);
|
|
34
34
|
spinner.succeed( '[akfun]当前配置数据已输出至akfun-build-config.js中!');
|
|
35
35
|
} else {
|
|
36
|
-
console.log(`不能识别type=${type}。`)
|
|
36
|
+
console.log(`不能识别type=${type}。`);
|
|
37
37
|
}
|
|
38
38
|
};
|
package/module/main.js
CHANGED
|
@@ -2,11 +2,24 @@
|
|
|
2
2
|
const buildAction = require('../src/build.js'); // 构建脚本:生产环境
|
|
3
3
|
const devAction = require('../src/dev-server.js'); // 构建脚本:开发环境
|
|
4
4
|
const build2esm = require('../src/build2esm.js'); // 构建esm输出模块
|
|
5
|
+
const inspect = require('./inspect.js');
|
|
6
|
+
const gitClone = require('../src/utils/gitClone.js');
|
|
7
|
+
const createFile = require('../src/utils/createFile');
|
|
8
|
+
const {resolve} = require('../src/utils/pathUtils');
|
|
9
|
+
const getConfigObj = require('../src/utils/getConfigObj');
|
|
10
|
+
const deepMergeConfig = require('../src/utils/deepMergeConfig');
|
|
5
11
|
const getCurWebpackConfig = require('../src/utils/getCurWebpackConfig.js'); // 用于获取当前webpack配置的方法
|
|
6
12
|
|
|
7
13
|
module.exports = {
|
|
8
14
|
dev: devAction,
|
|
9
15
|
build: buildAction,
|
|
10
16
|
build2esm,
|
|
17
|
+
inspect,
|
|
18
|
+
gitClone,
|
|
19
|
+
createFile,
|
|
20
|
+
resolve,
|
|
21
|
+
getConfigObj,
|
|
22
|
+
deepMergeConfig,
|
|
23
|
+
getCurWebpackConfig,
|
|
11
24
|
curWebpackBaseConfPath: getCurWebpackConfig('base'),
|
|
12
25
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akfun",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "前端脚手架:支持Vue技术栈和react技术栈",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"前端工程",
|
|
@@ -73,7 +73,6 @@
|
|
|
73
73
|
"@rollup/plugin-node-resolve": "^9.0.0",
|
|
74
74
|
"@typescript-eslint/eslint-plugin": "^3.9.0",
|
|
75
75
|
"@typescript-eslint/parser": "^3.9.0",
|
|
76
|
-
"eslint-config-prettier": "^7.2.0",
|
|
77
76
|
"@vue/compiler-sfc": "^3.0.0-rc.10",
|
|
78
77
|
"@vue/eslint-config-typescript": "^5.0.2",
|
|
79
78
|
"autoprefixer": "^9.8.0",
|
|
@@ -92,6 +91,7 @@
|
|
|
92
91
|
"es6-promise-polyfill": "^1.2.0",
|
|
93
92
|
"eslint": "^7.2.0",
|
|
94
93
|
"eslint-config-airbnb-base": "^14.1.0",
|
|
94
|
+
"eslint-config-prettier": "^7.2.0",
|
|
95
95
|
"eslint-friendly-formatter": "^4.0.1",
|
|
96
96
|
"eslint-import-resolver-webpack": "^0.12.1",
|
|
97
97
|
"eslint-loader": "^4.0.2",
|
|
@@ -112,6 +112,7 @@
|
|
|
112
112
|
"http-proxy-middleware": "^1.0.4",
|
|
113
113
|
"inquirer": "^7.3.3",
|
|
114
114
|
"mini-css-extract-plugin": "^0.9.0",
|
|
115
|
+
"monaco-editor-webpack-plugin": "6.0.0",
|
|
115
116
|
"node-sass": "^4.14.1",
|
|
116
117
|
"opn": "^6.0.0",
|
|
117
118
|
"optimize-css-assets-webpack-plugin": "^5.0.3",
|
|
@@ -152,8 +153,8 @@
|
|
|
152
153
|
"webpack-dev-middleware": "^3.7.2",
|
|
153
154
|
"webpack-hot-middleware": "^2.25.0",
|
|
154
155
|
"webpack-merge": "^4.2.2",
|
|
155
|
-
"
|
|
156
|
-
"
|
|
156
|
+
"webpack-node-externals": "^3.0.0",
|
|
157
|
+
"yargs": "^12.0.2"
|
|
157
158
|
},
|
|
158
159
|
"devDependencies": {
|
|
159
160
|
"@commitlint/cli": "^8.3.5",
|
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
|
|
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,101 @@
|
|
|
1
|
+
// 统一路径解析:
|
|
2
|
+
const { resolve } = require('../utils/pathUtils');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* akfun脚手架赋予当前项目的默认配置
|
|
6
|
+
*/
|
|
7
|
+
const defaultAKFunConfig = {
|
|
8
|
+
settings: {
|
|
9
|
+
enableESLint: false, // 是否开启ESLint,默认开启ESLint检测代码格式
|
|
10
|
+
enableESLintFix: false, // 是否ESLint自动修正代码格式
|
|
11
|
+
enableStyleLint: false, // 是否开启StyleLint,默认开启ESLint检测代码格式
|
|
12
|
+
enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
|
|
13
|
+
},
|
|
14
|
+
webpack: {
|
|
15
|
+
resolve: {
|
|
16
|
+
// webpack的resolve配置
|
|
17
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.json'], // 用于配置webpack在尝试过程中用到的后缀列表
|
|
18
|
+
alias: {
|
|
19
|
+
'@': resolve('src'),
|
|
20
|
+
$components: resolve('src/components'),
|
|
21
|
+
$pages: resolve('src/pages'),
|
|
22
|
+
$plugins: resolve('src/plugins'),
|
|
23
|
+
$utils: resolve('src/utils')
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
createDeclaration: false, // 打包时是否创建ts声明文件
|
|
27
|
+
ignoreNodeModules: false, // 打包时是否忽略 node_modules
|
|
28
|
+
externals: [], // 从输出的 bundle 中排除依赖
|
|
29
|
+
sassResources: []
|
|
30
|
+
},
|
|
31
|
+
envParams: {
|
|
32
|
+
// 项目系统环境变量
|
|
33
|
+
common: {
|
|
34
|
+
// 通用参数
|
|
35
|
+
'#version#': '20200810.1'
|
|
36
|
+
},
|
|
37
|
+
local: {
|
|
38
|
+
// 本地开发环境
|
|
39
|
+
'#dataApiBase#': 'http://localhost:1024', // 数据接口根地址
|
|
40
|
+
'#assetsPublicPath#': 'http://localhost:1024', // 静态资源根地址
|
|
41
|
+
'#routeBasePath#': '/' // 路由根地址
|
|
42
|
+
},
|
|
43
|
+
online: {
|
|
44
|
+
// 线上正式环境配置参数
|
|
45
|
+
'#dataApiBase#': '/', // 数据接口根地址 "//xxx.cn/"格式
|
|
46
|
+
'#assetsPublicPath#': '', // 静态资源根地址 "//xxx.cn/_spa/projectName"格式
|
|
47
|
+
'#routeBasePath#': '/' // 路由根地址 "/_spa/projectName/"格式
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
dev: {
|
|
51
|
+
// 用于开启本地调试模式的相关配置信息
|
|
52
|
+
NODE_ENV: 'development',
|
|
53
|
+
port: 80,
|
|
54
|
+
autoOpenBrowser: true,
|
|
55
|
+
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
56
|
+
assetsSubDirectory: '',
|
|
57
|
+
hostname: 'localhost',
|
|
58
|
+
proxyTable: {},
|
|
59
|
+
/** CSS Sourcemaps off by default because relative paths are "buggy"
|
|
60
|
+
* with this option, according to the CSS-Loader README
|
|
61
|
+
* (https://github.com/webpack/css-loader#sourcemaps)
|
|
62
|
+
* In our experience, they generally work as expected,
|
|
63
|
+
* just be aware of this issue when enabling this option.
|
|
64
|
+
*/
|
|
65
|
+
cssSourceMap: false
|
|
66
|
+
},
|
|
67
|
+
build: {
|
|
68
|
+
// 用于构建生产环境代码的相关配置信息
|
|
69
|
+
NODE_ENV: 'production', // production 模式,会启动UglifyJsPlugin服务
|
|
70
|
+
assetsRoot: resolve('dist'), // 编译完成的文件存放路径
|
|
71
|
+
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
72
|
+
assetsSubDirectory: '', // 资源引用二级路径
|
|
73
|
+
productionSourceMap: false,
|
|
74
|
+
// Gzip off by default as many popular public hosts such as
|
|
75
|
+
// Surge or Netlify already gzip all public assets for you.
|
|
76
|
+
// Before setting to `true`, make sure to:
|
|
77
|
+
// npm install --save-dev compression-webpack-plugin
|
|
78
|
+
productionGzip: false,
|
|
79
|
+
productionGzipExtensions: ['js', 'css', 'json'],
|
|
80
|
+
// Run the build command with an extra argument to
|
|
81
|
+
// View the bundle analyzer report after build finishes:
|
|
82
|
+
// `npm run build --report`
|
|
83
|
+
// Set to `true` or `false` to always turn it on or off
|
|
84
|
+
bundleAnalyzerReport: false
|
|
85
|
+
},
|
|
86
|
+
build2lib: {
|
|
87
|
+
// 用于构建第三方功能包的配置文件
|
|
88
|
+
NODE_ENV: 'production',
|
|
89
|
+
libraryName: '', // 构建第三方功能包时最后导出的引用变量名
|
|
90
|
+
assetsRoot: resolve('dist'), // 编译完成的文件存放路径
|
|
91
|
+
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
92
|
+
assetsSubDirectory: '', // 资源引用二级路径
|
|
93
|
+
productionSourceMap: false,
|
|
94
|
+
productionGzip: false,
|
|
95
|
+
productionGzipExtensions: ['js', 'css', 'json'],
|
|
96
|
+
bundleAnalyzerReport: false
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// 备注:数组类型则直接覆盖
|
|
101
|
+
module.exports = defaultAKFunConfig;
|
package/src/config/index.js
CHANGED
|
@@ -1,110 +1,15 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const deepMerge = require('deepmerge');
|
|
3
1
|
// 统一路径解析:
|
|
4
2
|
const { resolve } = require('../utils/pathUtils');
|
|
3
|
+
const defaultAKFunConfig = require('./default.config');
|
|
5
4
|
const getConfigObj = require('../utils/getConfigObj');
|
|
5
|
+
const deepMergeConfig = require('../utils/deepMergeConfig');
|
|
6
6
|
|
|
7
7
|
/** akfun脚手架赋予当前项目的默认配置
|
|
8
8
|
* 备注:项目根目录的akfun.config.js的配置内容优先级高于defultAKFunConfig
|
|
9
9
|
*/
|
|
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
10
|
|
|
103
11
|
// 从项目根目录获取当前项目的配置文件
|
|
104
12
|
const curProjectConfig = getConfigObj(resolve('akfun.config.js'));
|
|
105
13
|
|
|
106
|
-
// module.exports = Object.assign(defaultAKFunConfig, curProjectConfig);
|
|
107
|
-
|
|
108
|
-
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
|
|
109
14
|
// 备注:数组类型则直接覆盖
|
|
110
|
-
module.exports =
|
|
15
|
+
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
|
|
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,将编译后的文件暂存到内存中
|
|
@@ -22,7 +22,7 @@ module.exports = {
|
|
|
22
22
|
},
|
|
23
23
|
resolve: {
|
|
24
24
|
// webpack的resolve配置
|
|
25
|
-
extensions: ['.js', '.jsx', '.vue', 'json'], // 用于配置webpack在尝试过程中用到的后缀列表
|
|
25
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', 'json'], // 用于配置webpack在尝试过程中用到的后缀列表
|
|
26
26
|
alias: {
|
|
27
27
|
'@': resolve('src'),
|
|
28
28
|
$components: resolve('src/components'),
|
|
@@ -31,6 +31,8 @@ module.exports = {
|
|
|
31
31
|
$utils: resolve('src/utils')
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
+
createDeclaration: false, // 打包时是否创建ts声明文件
|
|
35
|
+
ignoreNodeModules: false, // 打包时是否忽略 node_modules
|
|
34
36
|
externals: [], // 从输出的 bundle 中排除依赖
|
|
35
37
|
template: resolve('src/index.html'), // 默认使用的页面模板
|
|
36
38
|
sassResources: []
|
|
@@ -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;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 用于获取当前项目配置文件
|
|
3
3
|
*/
|
|
4
|
-
module.exports = (type) => {
|
|
4
|
+
module.exports = (type, akfunConfig) => {
|
|
5
5
|
let curConfig = {};
|
|
6
6
|
if (type === 'dev') {
|
|
7
|
-
curConfig = require('../webpack/webpack.dev.conf')();
|
|
7
|
+
curConfig = require('../webpack/webpack.dev.conf')(akfunConfig);
|
|
8
8
|
} else if (type === 'lib') {
|
|
9
|
-
curConfig = require('../webpack/webpack.library.conf')();
|
|
9
|
+
curConfig = require('../webpack/webpack.library.conf')(akfunConfig);
|
|
10
10
|
} else if (type === 'build') {
|
|
11
|
-
curConfig = require('../webpack/webpack.prod.conf')();
|
|
11
|
+
curConfig = require('../webpack/webpack.prod.conf')(akfunConfig);
|
|
12
12
|
} else if (type === 'base') {
|
|
13
|
-
curConfig = require('../webpack/webpack.base.conf')();
|
|
13
|
+
curConfig = require('../webpack/webpack.base.conf')(akfunConfig);
|
|
14
14
|
}
|
|
15
15
|
return curConfig;
|
|
16
16
|
};
|
|
@@ -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
|
|
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
|
|
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);
|
|
@@ -43,7 +44,9 @@ module.exports = () => {
|
|
|
43
44
|
'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV)
|
|
44
45
|
}),
|
|
45
46
|
new MiniCssExtractPlugin({
|
|
46
|
-
filename: utils.assetsPath('index.css'),
|
|
47
|
+
// filename: utils.assetsPath('index.css'),
|
|
48
|
+
filename: "[name].css",
|
|
49
|
+
chunkFilename: "[id].css",
|
|
47
50
|
ignoreOrder: false
|
|
48
51
|
}),
|
|
49
52
|
new OptimizeCSSPlugin({
|
|
@@ -11,6 +11,7 @@ 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
13
|
const nodeExternals = require('webpack-node-externals');
|
|
14
|
+
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
14
15
|
|
|
15
16
|
const utils = require('./loaderUtils');
|
|
16
17
|
const { resolve } = require('../utils/pathUtils'); // 统一路径解析
|
|
@@ -18,10 +19,11 @@ const getJsEntries = require('../utils/jsEntries');
|
|
|
18
19
|
const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
|
|
19
20
|
const { isArray } = require('../utils/typeof');
|
|
20
21
|
// 引入当前项目配置文件
|
|
21
|
-
const
|
|
22
|
+
const projectConfig = require('../config/index');
|
|
22
23
|
const getBaseWebpackConfig = require('./webpack.base.conf');
|
|
23
24
|
|
|
24
|
-
module.exports = () => {
|
|
25
|
+
module.exports = (akfunConfig) => {
|
|
26
|
+
let config = akfunConfig || projectConfig; // 默认使用执行命令目录下的配置数据
|
|
25
27
|
const curEnvConfig = config.build || {}; // 当前执行环境配置
|
|
26
28
|
// 获取webpack基本配置
|
|
27
29
|
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig);
|
|
@@ -175,6 +177,11 @@ module.exports = () => {
|
|
|
175
177
|
})
|
|
176
178
|
);
|
|
177
179
|
}
|
|
180
|
+
|
|
181
|
+
// 是否开启
|
|
182
|
+
if (curEnvConfig.openMonacoWebpackPlugin) {
|
|
183
|
+
webpackProdConfig.plugins.push(new MonacoWebpackPlugin());
|
|
184
|
+
}
|
|
178
185
|
|
|
179
186
|
if (curEnvConfig.bundleAnalyzerReport) {
|
|
180
187
|
webpackProdConfig.plugins.push(new BundleAnalyzerPlugin());
|