akfun 1.5.11 → 1.5.16
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 +48 -11
- package/bin/akfun.js +1 -1
- package/{build → module}/akfunInit.js +3 -2
- package/{build → module}/index.js +8 -1
- package/{build → module}/inspect.js +0 -0
- package/{build → module}/main.js +0 -0
- package/package.json +6 -5
- package/src/config/.eslintrc.ts.js +3 -0
- package/src/config/index.js +7 -11
- package/src/config/tsconfig.json +2 -2
- package/src/initData/akfun-package.json +3 -3
- package/src/utils/getConfigObj.js +1 -1
- package/src/utils/getProjectDir.js +16 -0
- package/src/utils/gitClone.js +3 -3
- package/src/webpack/webpack.base.conf.js +23 -10
- package/src/webpack/webpack.dev.conf.js +10 -9
- package/src/webpack/webpack.library.conf.js +17 -13
- package/src/webpack/webpack.prod.conf.js +26 -13
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# AKFun 前端脚手架
|
|
2
|
-
> AKFun 是一个基于 Webpack4.0 和 rollup 的前端多场景打包工具,支持多种技术栈:Vue技术栈、React技术栈、React&TS技术栈
|
|
3
|
-
-
|
|
2
|
+
> AKFun 是一个基于 Webpack4.0 和 rollup 的前端多场景打包工具,支持多种技术栈:Vue技术栈、React技术栈、React&TS技术栈
|
|
3
|
+
- 核心理念:提供完整&全面的前端工程能力,并尽可能屏蔽掉前端工程相关配置,让开发者更专注业务研发工作。
|
|
4
|
+
- 技术栈:node/webpack4.0/rollup/babel/eslint/stylelint
|
|
4
5
|
|
|
5
6
|
## 特性
|
|
6
7
|
- ⚡️ 零配置,开箱即用
|
|
7
8
|
- 👏 支持Vue和React项目的调试和构建
|
|
8
9
|
- 📤 支持单页面和多页面
|
|
9
|
-
- 💪 提供三种构建场景:
|
|
10
|
-
- ❤️ 开放配置能力:
|
|
10
|
+
- 💪 提供三种构建场景: 本地开发模式(包含热更新、接口代理等功能)、生产环境代码构建、library库构建(支持umd和esm的打包能力)
|
|
11
|
+
- ❤️ 开放配置能力: 可配置构建入口文件、开启ESLint代码检测、接口代理等
|
|
11
12
|
- 👍 支持 [Autoprefixer](https://github.com/postcss/autoprefixer#readme)、[Sass](https://sass-lang.com/)、[PostCSS](https://postcss.org/)、[ESLint](http://eslint.cn/)、[StyleLint](https://stylelint.io/)
|
|
12
13
|
- ❤️ 支持项目系统参数自动批量替换 [params-replace-loader](https://www.npmjs.com/package/params-replace-loader)
|
|
13
14
|
- 😀 提供完整的Vue和React项目模板
|
|
@@ -144,7 +145,7 @@ $ yarn add akfun --dev 或者 npm i akfun --save-dev
|
|
|
144
145
|
|
|
145
146
|
6. **关于多页面**
|
|
146
147
|
1. 当akfun.config.js的entry只有一个入口配置,且对应的构建入口文件不存在时,AKFun会自动从src/pages中获取构建入口(支持多页面多模板)
|
|
147
|
-
2. 多页面模式下,会自动将src/pages中以.ts、.tsx、.js、.jsx结尾(对应的匹配正则:/\.[tj]sx
|
|
148
|
+
2. 多页面模式下,会自动将src/pages中以.ts、.tsx、.js、.jsx结尾(对应的匹配正则:/\.[tj]sx?$/)的文件作为构建入口文件,同时将同名的html文件作为当前页面模板
|
|
148
149
|
|
|
149
150
|
7. **关于多页面多模板**
|
|
150
151
|
1. 只有dev和build的构建过程中才会使用到页面模板,build2lib构建中不会将打包完成的代码输出到页面模板中
|
|
@@ -245,7 +246,43 @@ module.exports = {
|
|
|
245
246
|
}
|
|
246
247
|
```
|
|
247
248
|
|
|
248
|
-
7.
|
|
249
|
+
7. 打包忽略node_modules配置项: ignoreNodeModules(默认为false)
|
|
250
|
+
> 打包过程中,忽略node_modules中的依赖文件,不注入到bundle中,减少最后生成代码体积
|
|
251
|
+
```bash
|
|
252
|
+
module.exports = {
|
|
253
|
+
...
|
|
254
|
+
webpack: {
|
|
255
|
+
ignoreNodeModules: true,
|
|
256
|
+
}
|
|
257
|
+
...
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
8. 是否生成ts声明文件配置项: createDeclaration(默认为false)
|
|
262
|
+
> 构建ts项目中,可以选择是否生成ts声明文件
|
|
263
|
+
```bash
|
|
264
|
+
module.exports = {
|
|
265
|
+
...
|
|
266
|
+
webpack: {
|
|
267
|
+
createDeclaration: true,
|
|
268
|
+
}
|
|
269
|
+
...
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
9. 配置项目源码目录(工程有效目录范围): projectDir
|
|
274
|
+
> 构建项目中,设置生效的目录(可同时设置多个目录),用于提高前端工程执行效率。可以不配置,默认为['./src']
|
|
275
|
+
```bash
|
|
276
|
+
module.exports = {
|
|
277
|
+
...
|
|
278
|
+
webpack: {
|
|
279
|
+
projectDir: ['./src'],
|
|
280
|
+
}
|
|
281
|
+
...
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
10. 项目源码环境变量批量替换
|
|
249
286
|
> [关于params-replace-loader的使用方法](https://www.npmjs.com/package/params-replace-loader)
|
|
250
287
|
```bash
|
|
251
288
|
module.exports = {
|
|
@@ -264,7 +301,7 @@ module.exports = {
|
|
|
264
301
|
}
|
|
265
302
|
```
|
|
266
303
|
|
|
267
|
-
|
|
304
|
+
11. 接口代理配置:目前只有dev本地开发调试模式下会启动
|
|
268
305
|
> [关于proxyTable的配置方法](https://www.webpackjs.com/configuration/dev-server/#devserver-proxy)
|
|
269
306
|
```bash
|
|
270
307
|
module.exports = {
|
|
@@ -277,7 +314,7 @@ module.exports = {
|
|
|
277
314
|
}
|
|
278
315
|
```
|
|
279
316
|
|
|
280
|
-
|
|
317
|
+
12. 用于开启本地调试模式的相关配置信息
|
|
281
318
|
```bash
|
|
282
319
|
module.exports = {
|
|
283
320
|
...
|
|
@@ -301,7 +338,7 @@ module.exports = {
|
|
|
301
338
|
}
|
|
302
339
|
```
|
|
303
340
|
|
|
304
|
-
|
|
341
|
+
13. 用于构建生产环境代码的相关配置信息
|
|
305
342
|
```bash
|
|
306
343
|
module.exports = {
|
|
307
344
|
...
|
|
@@ -319,7 +356,7 @@ module.exports = {
|
|
|
319
356
|
}
|
|
320
357
|
```
|
|
321
358
|
|
|
322
|
-
|
|
359
|
+
14. 用于构建第三方功能包的配置(以umd格式输出)
|
|
323
360
|
```bash
|
|
324
361
|
module.exports = {
|
|
325
362
|
...
|
|
@@ -338,7 +375,7 @@ module.exports = {
|
|
|
338
375
|
}
|
|
339
376
|
```
|
|
340
377
|
|
|
341
|
-
|
|
378
|
+
15. 用于构建esm格式的第三方功能包配置
|
|
342
379
|
```bash
|
|
343
380
|
module.exports = {
|
|
344
381
|
...
|
package/bin/akfun.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
require('../
|
|
2
|
+
require('../module/index');
|
|
@@ -3,15 +3,16 @@ const gitClone = require('../src/utils/gitClone');
|
|
|
3
3
|
const templateList = {
|
|
4
4
|
'vue': 'git@github.com:wibetter/akfun-vue-template.git',
|
|
5
5
|
'react': 'git@github.com:wibetter/akfun-react-template.git',
|
|
6
|
+
'react&ts': 'git@github.com:wibetter/akfun-react-ts-template.git',
|
|
6
7
|
'library': 'git@github.com:wibetter/json-utils.git',
|
|
7
8
|
'json-editor': 'git@github.com:wibetter/json-editor.git',
|
|
8
9
|
'json-schema-editor': 'git@github.com:wibetter/json-schema-editor.git',
|
|
9
10
|
'pigNews': 'git@github.com:wibetter/pigNews.git',
|
|
10
11
|
};
|
|
11
12
|
|
|
12
|
-
const akfunInit = function (type,
|
|
13
|
+
const akfunInit = function (type, dir, projectName) {
|
|
13
14
|
const currentTemplateUrl = templateList[type || 'react'];
|
|
14
|
-
gitClone(currentTemplateUrl,
|
|
15
|
+
gitClone(currentTemplateUrl, dir || 'akfunProject', () => {});
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
module.exports = akfunInit;
|
|
@@ -25,7 +25,7 @@ const bigTip = figlet.textSync('AKFun', {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
console.log(chalk.green(bigTip));
|
|
28
|
-
console.log(`当前版本:v${akfunPackage.version}.\n`);
|
|
28
|
+
console.log(chalk.green(`当前版本:v${akfunPackage.version}.\n`));
|
|
29
29
|
|
|
30
30
|
let argv = yargs
|
|
31
31
|
.command(
|
|
@@ -55,6 +55,7 @@ let argv = yargs
|
|
|
55
55
|
akfunInit(argv.type, argv.dir, argv.name);
|
|
56
56
|
} else {
|
|
57
57
|
const questions = [];
|
|
58
|
+
// 初始化项目模板时,当用户未设置项目类型type时,以列表形式展示当前可以使用的项目模板
|
|
58
59
|
if (!argv.type) {
|
|
59
60
|
questions.push({
|
|
60
61
|
name : 'type',
|
|
@@ -67,6 +68,11 @@ let argv = yargs
|
|
|
67
68
|
value : 'react',
|
|
68
69
|
short : 'react',
|
|
69
70
|
},
|
|
71
|
+
{
|
|
72
|
+
name : 'react&ts项目',
|
|
73
|
+
value : 'react&ts',
|
|
74
|
+
short : 'react&ts',
|
|
75
|
+
},
|
|
70
76
|
{
|
|
71
77
|
name : 'vue项目',
|
|
72
78
|
value : 'vue',
|
|
@@ -80,6 +86,7 @@ let argv = yargs
|
|
|
80
86
|
],
|
|
81
87
|
});
|
|
82
88
|
}
|
|
89
|
+
// 当用户未设置存放项目的目录地址时,提示用户
|
|
83
90
|
if (!argv.dir) {
|
|
84
91
|
questions.push({
|
|
85
92
|
name : 'dir',
|
|
File without changes
|
package/{build → module}/main.js
RENAMED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akfun",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.16",
|
|
4
4
|
"description": "前端脚手架:支持Vue技术栈和react技术栈",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"前端工程",
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"vue项目脚手架",
|
|
11
11
|
"lib库构建工具"
|
|
12
12
|
],
|
|
13
|
-
"author": "
|
|
13
|
+
"author": "wibetter",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"bin": {
|
|
16
16
|
"akfun": "./bin/akfun.js"
|
|
17
17
|
},
|
|
18
|
-
"main": "
|
|
18
|
+
"main": "module/main.js",
|
|
19
19
|
"scripts": {
|
|
20
20
|
"akfun": "akfun",
|
|
21
21
|
"format": "prettier --write \"src/**/**/*.{js,vue,tsx,ts,scss,json}\""
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"bin/*",
|
|
25
|
-
"
|
|
25
|
+
"module/*",
|
|
26
26
|
"src/*"
|
|
27
27
|
],
|
|
28
28
|
"husky": {
|
|
@@ -152,7 +152,8 @@
|
|
|
152
152
|
"webpack-dev-middleware": "^3.7.2",
|
|
153
153
|
"webpack-hot-middleware": "^2.25.0",
|
|
154
154
|
"webpack-merge": "^4.2.2",
|
|
155
|
-
"yargs": "^12.0.2"
|
|
155
|
+
"yargs": "^12.0.2",
|
|
156
|
+
"webpack-node-externals": "^3.0.0"
|
|
156
157
|
},
|
|
157
158
|
"devDependencies": {
|
|
158
159
|
"@commitlint/cli": "^8.3.5",
|
package/src/config/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const getConfigObj = require('../utils/getConfigObj');
|
|
|
7
7
|
/** akfun脚手架赋予当前项目的默认配置
|
|
8
8
|
* 备注:项目根目录的akfun.config.js的配置内容优先级高于defultAKFunConfig
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const defaultAKFunConfig = {
|
|
11
11
|
settings: {
|
|
12
12
|
enableESLint: false, // 是否开启ESLint,默认开启ESLint检测代码格式
|
|
13
13
|
enableESLintFix: false, // 是否ESLint自动修正代码格式
|
|
@@ -26,6 +26,8 @@ const defultAKFunConfig = {
|
|
|
26
26
|
$utils: resolve('src/utils')
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
+
createDeclaration: false, // 打包时是否创建ts声明文件
|
|
30
|
+
ignoreNodeModules: false, // 打包时是否忽略 node_modules
|
|
29
31
|
externals: [], // 从输出的 bundle 中排除依赖
|
|
30
32
|
sassResources: []
|
|
31
33
|
},
|
|
@@ -56,13 +58,7 @@ const defultAKFunConfig = {
|
|
|
56
58
|
assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
|
|
57
59
|
assetsSubDirectory: '',
|
|
58
60
|
hostname: 'localhost',
|
|
59
|
-
proxyTable: {
|
|
60
|
-
'/apiTest': {
|
|
61
|
-
target: 'http://api-test.com.cn', // 不支持跨域的接口根地址
|
|
62
|
-
ws: true,
|
|
63
|
-
changeOrigin: true
|
|
64
|
-
}
|
|
65
|
-
},
|
|
61
|
+
proxyTable: {},
|
|
66
62
|
/** CSS Sourcemaps off by default because relative paths are "buggy"
|
|
67
63
|
* with this option, according to the CSS-Loader README
|
|
68
64
|
* (https://github.com/webpack/css-loader#sourcemaps)
|
|
@@ -105,10 +101,10 @@ const defultAKFunConfig = {
|
|
|
105
101
|
};
|
|
106
102
|
|
|
107
103
|
// 从项目根目录获取当前项目的配置文件
|
|
108
|
-
const
|
|
104
|
+
const curProjectConfig = getConfigObj(resolve('akfun.config.js'));
|
|
109
105
|
|
|
110
|
-
// module.exports = Object.assign(
|
|
106
|
+
// module.exports = Object.assign(defaultAKFunConfig, curProjectConfig);
|
|
111
107
|
|
|
112
108
|
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
|
|
113
109
|
// 备注:数组类型则直接覆盖
|
|
114
|
-
module.exports = deepMerge(
|
|
110
|
+
module.exports = deepMerge(defaultAKFunConfig, curProjectConfig, { arrayMerge: overwriteMerge });
|
package/src/config/tsconfig.json
CHANGED
|
@@ -63,6 +63,6 @@
|
|
|
63
63
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
|
|
64
64
|
"suppressImplicitAnyIndexErrors": true /* Suppress --noImplicitAny errors for indexing objects lacking index signatures. See issue #1232 for more details. */
|
|
65
65
|
},
|
|
66
|
-
"include": ["
|
|
67
|
-
"exclude": []
|
|
66
|
+
"include": ["src"],
|
|
67
|
+
"exclude": ["node_modules"]
|
|
68
68
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akfun",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"description": "前端脚手架:支持Vue技术站和react技术栈",
|
|
5
5
|
"keywords": ["前端工程", "前端脚手架", "webpack"],
|
|
6
6
|
"author": "ldan@wibetter",
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"bin": {
|
|
9
9
|
"akfun": "./bin/akfun.js"
|
|
10
10
|
},
|
|
11
|
-
"main": "
|
|
11
|
+
"main": "module/main.js",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"akfun": "akfun",
|
|
14
14
|
"lint": "eslint --ext .js,.vue src",
|
|
15
15
|
"lintFix": "eslint --ext .js,.vue src --fix",
|
|
16
16
|
"format": "prettier --write \"src/**/**/*.{js,vue,tsx,ts,scss,json}\""
|
|
17
17
|
},
|
|
18
|
-
"files": ["bin/*", "
|
|
18
|
+
"files": ["bin/*", "module/*", "src/*"],
|
|
19
19
|
"husky": {
|
|
20
20
|
"hooks": {
|
|
21
21
|
"pre-commit": "lint-staged",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const { resolveToCurrentRoot } = require('./pathUtils');
|
|
2
|
+
const { isArray, isString } = require('../utils/typeof');
|
|
3
|
+
|
|
4
|
+
module.exports = (_projectDir) => {
|
|
5
|
+
const curProjectDir = [];
|
|
6
|
+
if (!_projectDir) {
|
|
7
|
+
curProjectDir.push(resolveToCurrentRoot('./src'));
|
|
8
|
+
} else if (isArray(_projectDir)) {
|
|
9
|
+
_projectDir.forEach((dir) => {
|
|
10
|
+
curProjectDir.push(resolveToCurrentRoot(dir));
|
|
11
|
+
});
|
|
12
|
+
} else if (isString(_projectDir)) {
|
|
13
|
+
curProjectDir.push(resolveToCurrentRoot(_projectDir));
|
|
14
|
+
}
|
|
15
|
+
return curProjectDir;
|
|
16
|
+
};
|
package/src/utils/gitClone.js
CHANGED
|
@@ -4,17 +4,17 @@ const gitclone = require('git-clone');
|
|
|
4
4
|
const rm = require('rimraf').sync;
|
|
5
5
|
const { resolveToCurrentRoot } = require('../utils/pathUtils');
|
|
6
6
|
|
|
7
|
-
function gitClone(gitUrl,
|
|
7
|
+
function gitClone(gitUrl, dir, callback) {
|
|
8
8
|
const spinner = ora('[akfun]正在加载项目模板...').start();
|
|
9
9
|
gitclone(
|
|
10
10
|
gitUrl,
|
|
11
|
-
resolveToCurrentRoot(
|
|
11
|
+
resolveToCurrentRoot(dir),
|
|
12
12
|
{
|
|
13
13
|
checkout: 'master'
|
|
14
14
|
},
|
|
15
15
|
(err) => {
|
|
16
16
|
if (err === undefined) {
|
|
17
|
-
rm(resolveToCurrentRoot(path.resolve(
|
|
17
|
+
rm(resolveToCurrentRoot(path.resolve(dir, '.git')));
|
|
18
18
|
spinner.succeed('[akfun]项目模板加载完成!');
|
|
19
19
|
callback();
|
|
20
20
|
} else {
|
|
@@ -7,6 +7,7 @@ const utils = require('./loaderUtils');
|
|
|
7
7
|
const vueLoaderConfig = require('./vue-loader.conf');
|
|
8
8
|
const { resolve, resolveToCurrentRoot, catchCurPackageJson } = require('../utils/pathUtils');
|
|
9
9
|
const getConfigObj = require('../utils/getConfigObj');
|
|
10
|
+
const getProjectDir = require('../utils/getProjectDir');
|
|
10
11
|
const catchVuePages = require('../utils/catchVuePages'); // 用于获取当前项目中的vue单文件
|
|
11
12
|
// 引入当前项目配置文件
|
|
12
13
|
const config = require('../config/index');
|
|
@@ -28,7 +29,14 @@ const BannerPack = new webpack.BannerPlugin({
|
|
|
28
29
|
entryOnly: true // 只在入口 chunks 文件中添加
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* webpack.base.conf.js
|
|
34
|
+
* 主要用于设置 rules 和 通用插件
|
|
35
|
+
*/
|
|
36
|
+
module.exports = (option) => {
|
|
37
|
+
const curEnvConfig = option || {}; // 用于接收当前运行环境配置变量
|
|
38
|
+
// 获取当前项目目录
|
|
39
|
+
const curProjectDir = getProjectDir(config.webpack.projectDir);
|
|
32
40
|
const webpackConfig = {
|
|
33
41
|
entry: config.webpack.entry,
|
|
34
42
|
/*
|
|
@@ -66,11 +74,17 @@ module.exports = () => {
|
|
|
66
74
|
options: babelConfig
|
|
67
75
|
},
|
|
68
76
|
{
|
|
69
|
-
loader: 'ts-loader'
|
|
70
|
-
|
|
77
|
+
loader: 'ts-loader',
|
|
78
|
+
options: {
|
|
79
|
+
// configFile: path.resolve(__dirname, '../config/tsconfig.json')
|
|
80
|
+
compilerOptions: {
|
|
81
|
+
declaration: config.webpack.createDeclaration || false,
|
|
82
|
+
outDir: curEnvConfig.assetsRoot || './dist'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
71
85
|
}
|
|
72
86
|
],
|
|
73
|
-
include: [resolve('src')],
|
|
87
|
+
include: curProjectDir, // [resolve('src')],
|
|
74
88
|
exclude: /node_modules/
|
|
75
89
|
},
|
|
76
90
|
{
|
|
@@ -81,7 +95,7 @@ module.exports = () => {
|
|
|
81
95
|
options: babelConfig
|
|
82
96
|
}
|
|
83
97
|
],
|
|
84
|
-
include: [resolve('src')],
|
|
98
|
+
include: curProjectDir, // [resolve('src')],
|
|
85
99
|
exclude: /node_modules/
|
|
86
100
|
},
|
|
87
101
|
{
|
|
@@ -123,7 +137,7 @@ module.exports = () => {
|
|
|
123
137
|
{
|
|
124
138
|
test: /\.(js|ts|tsx|jsx|vue|css|html)$/,
|
|
125
139
|
loader: 'params-replace-loader',
|
|
126
|
-
include: [resolve('src')],
|
|
140
|
+
include: curProjectDir, // [resolve('src')],
|
|
127
141
|
exclude: [/node_modules/, resolve('src/mock/data')], // 排除不需要进行校验的文件夹
|
|
128
142
|
options: config.envParams
|
|
129
143
|
}
|
|
@@ -135,7 +149,6 @@ module.exports = () => {
|
|
|
135
149
|
new VueLoaderPlugin()
|
|
136
150
|
]
|
|
137
151
|
};
|
|
138
|
-
|
|
139
152
|
// 是否开启ESLint
|
|
140
153
|
if (config.settings.enableESLint) {
|
|
141
154
|
// ts类型
|
|
@@ -143,7 +156,7 @@ module.exports = () => {
|
|
|
143
156
|
test: /\.tsx?$/,
|
|
144
157
|
loader: 'eslint-loader',
|
|
145
158
|
enforce: 'pre',
|
|
146
|
-
include: [resolve('src')],
|
|
159
|
+
include: curProjectDir, // [resolve('src')],
|
|
147
160
|
exclude: /node_modules/,
|
|
148
161
|
options: {
|
|
149
162
|
cache: true,
|
|
@@ -157,7 +170,7 @@ module.exports = () => {
|
|
|
157
170
|
test: /\.jsx?$/,
|
|
158
171
|
loader: 'eslint-loader',
|
|
159
172
|
enforce: 'pre',
|
|
160
|
-
include: [resolve('src')],
|
|
173
|
+
include: curProjectDir, // [resolve('src')],
|
|
161
174
|
exclude: /node_modules/,
|
|
162
175
|
options: {
|
|
163
176
|
cache: true, // the cache is written to the ./node_modules/.cache/eslint-loader director
|
|
@@ -171,7 +184,7 @@ module.exports = () => {
|
|
|
171
184
|
test: /\.vue$/,
|
|
172
185
|
loader: 'eslint-loader',
|
|
173
186
|
enforce: 'pre',
|
|
174
|
-
include: [resolve('src')],
|
|
187
|
+
include: curProjectDir, // [resolve('src')],
|
|
175
188
|
exclude: /node_modules/,
|
|
176
189
|
options: {
|
|
177
190
|
cache: true,
|
|
@@ -13,8 +13,9 @@ const entrys2htmlWebpackPlugin = require('../utils/entrys2htmlWebpackPlugin');
|
|
|
13
13
|
const { isArray } = require('../utils/typeof');
|
|
14
14
|
|
|
15
15
|
module.exports = () => {
|
|
16
|
+
const curEnvConfig = config.dev || {}; // 当前执行环境配置
|
|
16
17
|
// 获取webpack基本配置
|
|
17
|
-
const baseWebpackConfig = getBaseWebpackConfig();
|
|
18
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig);
|
|
18
19
|
|
|
19
20
|
// 获取页面模板地址
|
|
20
21
|
let curHtmlTemplate = path.resolve(__dirname, '../initData/template/index.html');
|
|
@@ -23,21 +24,21 @@ module.exports = () => {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
const webpackDevConfig = merge(baseWebpackConfig, {
|
|
26
|
-
mode:
|
|
27
|
+
mode: curEnvConfig.NODE_ENV, // development模式,会启动NamedChunksPlugin、NamedModulesPlugin服务
|
|
27
28
|
output: {
|
|
28
|
-
publicPath:
|
|
29
|
+
publicPath: curEnvConfig.assetsPublicPath // 引用地址:配置发布到线上资源的URL前缀
|
|
29
30
|
},
|
|
30
31
|
module: {
|
|
31
32
|
rules: utils.styleLoaders({
|
|
32
|
-
sourceMap:
|
|
33
|
+
sourceMap: curEnvConfig.cssSourceMap,
|
|
33
34
|
environment: 'dev'
|
|
34
35
|
})
|
|
35
36
|
},
|
|
36
37
|
// cheap-module-eval-source-map is faster for development
|
|
37
|
-
devtool: '#cheap-module-eval-source-map',
|
|
38
|
+
devtool: '#source-map', // '#cheap-module-eval-source-map',
|
|
38
39
|
plugins: [
|
|
39
40
|
new webpack.DefinePlugin({
|
|
40
|
-
'process.env.NODE_ENV': JSON.stringify(
|
|
41
|
+
'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV) // vue-router中根据此变量判断执行环境
|
|
41
42
|
}),
|
|
42
43
|
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
|
|
43
44
|
new webpack.HotModuleReplacementPlugin(),
|
|
@@ -48,8 +49,8 @@ module.exports = () => {
|
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
// 集成dev配置中的构建入口(优先级高于config.webpack.entry)
|
|
51
|
-
if (
|
|
52
|
-
webpackDevConfig.entry =
|
|
52
|
+
if (curEnvConfig.entry) {
|
|
53
|
+
webpackDevConfig.entry = curEnvConfig.entry; // 备注:会覆盖config.webpack.entry的配置
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
// 多页面多模板支持能力
|
|
@@ -81,7 +82,7 @@ module.exports = () => {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
//
|
|
85
|
+
// 使用用户自定义的多入口配置,生产对应的多页面多模板(优先使用用户的自定义页面模板)
|
|
85
86
|
const htmlWebpackPluginList = entrys2htmlWebpackPlugin(webpackDevConfig.entry, curHtmlTemplate);
|
|
86
87
|
htmlWebpackPluginList.forEach((htmlWebpackPlugin) => {
|
|
87
88
|
webpackDevConfig.plugins.push(htmlWebpackPlugin);
|
|
@@ -6,6 +6,7 @@ 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');
|
|
9
10
|
|
|
10
11
|
const utils = require('./loaderUtils');
|
|
11
12
|
// 引入当前项目配置文件
|
|
@@ -13,30 +14,33 @@ const config = require('../config/index');
|
|
|
13
14
|
const getBaseWebpackConfig = require('./webpack.base.conf');
|
|
14
15
|
|
|
15
16
|
module.exports = () => {
|
|
17
|
+
const curEnvConfig = config.build2lib || {}; // 当前执行环境配置
|
|
16
18
|
// 获取webpack基本配置
|
|
17
|
-
const baseWebpackConfig = getBaseWebpackConfig();
|
|
19
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig);
|
|
18
20
|
|
|
19
21
|
const webpackLibConfig = merge(baseWebpackConfig, {
|
|
20
|
-
mode:
|
|
22
|
+
mode: curEnvConfig.NODE_ENV, // production 模式,会启动UglifyJsPlugin服务
|
|
21
23
|
output: {
|
|
22
|
-
path:
|
|
24
|
+
path: curEnvConfig.assetsRoot, // 输出文件的存放在本地的目录
|
|
23
25
|
filename: '[name].umd.js',
|
|
24
26
|
publicPath: '',
|
|
25
|
-
library:
|
|
27
|
+
library: curEnvConfig.libraryName, // 指定类库名,主要用于直接引用的方式(比如使用script 标签)
|
|
26
28
|
globalObject: 'this', // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
|
|
27
29
|
libraryTarget: 'umd' // 定义打包方式Universal Module Definition,同时支持在CommonJS、AMD和全局变量使用
|
|
28
30
|
},
|
|
29
31
|
module: {
|
|
30
32
|
rules: utils.styleLoaders({
|
|
31
|
-
sourceMap:
|
|
33
|
+
sourceMap: curEnvConfig.productionSourceMap,
|
|
32
34
|
environment: 'prod'
|
|
33
35
|
})
|
|
34
36
|
},
|
|
35
|
-
devtool:
|
|
36
|
-
externals: config.webpack.
|
|
37
|
+
devtool: curEnvConfig.productionSourceMap ? '#source-map' : false, // '#source-map': 源码,false:压缩代码
|
|
38
|
+
externals: config.webpack.ignoreNodeModules
|
|
39
|
+
? [nodeExternals()].concat(config.webpack.externals)
|
|
40
|
+
: config.webpack.externals,
|
|
37
41
|
plugins: [
|
|
38
42
|
new webpack.DefinePlugin({
|
|
39
|
-
'process.env.NODE_ENV': JSON.stringify(
|
|
43
|
+
'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV)
|
|
40
44
|
}),
|
|
41
45
|
new MiniCssExtractPlugin({
|
|
42
46
|
filename: utils.assetsPath('index.css'),
|
|
@@ -53,10 +57,10 @@ module.exports = () => {
|
|
|
53
57
|
});
|
|
54
58
|
|
|
55
59
|
// 是否开启Gzip
|
|
56
|
-
if (
|
|
60
|
+
if (curEnvConfig.productionGzip) {
|
|
57
61
|
webpackLibConfig.plugins.push(
|
|
58
62
|
new CompressionWebpackPlugin({
|
|
59
|
-
test: new RegExp(`\\.(${
|
|
63
|
+
test: new RegExp(`\\.(${curEnvConfig.productionGzipExtensions.join('|')})$`),
|
|
60
64
|
filename: '[path].gz[query]',
|
|
61
65
|
algorithm: 'gzip',
|
|
62
66
|
threshold: 240,
|
|
@@ -65,13 +69,13 @@ module.exports = () => {
|
|
|
65
69
|
);
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
if (
|
|
72
|
+
if (curEnvConfig.bundleAnalyzerReport) {
|
|
69
73
|
webpackLibConfig.plugins.push(new BundleAnalyzerPlugin());
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
// 集成构建入口相关的配置
|
|
73
|
-
if (
|
|
74
|
-
webpackLibConfig.entry =
|
|
77
|
+
if (curEnvConfig.entry) {
|
|
78
|
+
webpackLibConfig.entry = curEnvConfig.entry; // 会覆盖config.webpack.entry的配置
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
return webpackLibConfig;
|
|
@@ -10,6 +10,7 @@ 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');
|
|
13
14
|
|
|
14
15
|
const utils = require('./loaderUtils');
|
|
15
16
|
const { resolve } = require('../utils/pathUtils'); // 统一路径解析
|
|
@@ -21,8 +22,9 @@ const config = require('../config/index');
|
|
|
21
22
|
const getBaseWebpackConfig = require('./webpack.base.conf');
|
|
22
23
|
|
|
23
24
|
module.exports = () => {
|
|
25
|
+
const curEnvConfig = config.build || {}; // 当前执行环境配置
|
|
24
26
|
// 获取webpack基本配置
|
|
25
|
-
const baseWebpackConfig = getBaseWebpackConfig();
|
|
27
|
+
const baseWebpackConfig = getBaseWebpackConfig(curEnvConfig);
|
|
26
28
|
// 获取页面模板地址
|
|
27
29
|
let curHtmlTemplate = path.resolve(__dirname, '../initData/template/index.html');
|
|
28
30
|
if (config.webpack.template) {
|
|
@@ -30,21 +32,32 @@ module.exports = () => {
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
const webpackProdConfig = merge(baseWebpackConfig, {
|
|
33
|
-
mode:
|
|
35
|
+
mode: curEnvConfig.NODE_ENV, // production 模式,会启动UglifyJsPlugin服务
|
|
36
|
+
/*
|
|
37
|
+
内置变量列表:
|
|
38
|
+
id: chunk的唯一标识,从0开始;
|
|
39
|
+
name: chunk的名称;
|
|
40
|
+
hash: chunk的唯一标识的Hash值;
|
|
41
|
+
chunkhash: chunk内容的Hash值;
|
|
42
|
+
其中hash和chunkhash的长度是可以指定的,[hash:8]代表取8位的Hash值,默认是20位。
|
|
43
|
+
*/
|
|
34
44
|
output: {
|
|
35
|
-
path:
|
|
36
|
-
publicPath:
|
|
45
|
+
path: curEnvConfig.assetsRoot, // 输出文件的存放在本地的目录
|
|
46
|
+
publicPath: curEnvConfig.assetsPublicPath, // 引用地址:配置发布到线上资源的URL前缀
|
|
37
47
|
filename: utils.assetsPath('scripts/chunk/[name].[contenthash:8].js'),
|
|
38
48
|
chunkFilename: utils.assetsPath('scripts/chunk/[name].[contenthash:8].js')
|
|
39
49
|
},
|
|
40
50
|
module: {
|
|
41
51
|
rules: utils.styleLoaders({
|
|
42
|
-
sourceMap:
|
|
52
|
+
sourceMap: curEnvConfig.productionSourceMap,
|
|
43
53
|
environment: 'prod'
|
|
44
54
|
})
|
|
45
55
|
},
|
|
56
|
+
externals: config.webpack.ignoreNodeModules
|
|
57
|
+
? [nodeExternals()].concat(config.webpack.externals)
|
|
58
|
+
: config.webpack.externals,
|
|
46
59
|
// devtool: '#cheap-module-eval-source-map', // 本地开发环境中的取值
|
|
47
|
-
devtool:
|
|
60
|
+
devtool: curEnvConfig.productionSourceMap ? '#source-map' : false, // 线上开发环境中的取值
|
|
48
61
|
optimization: {
|
|
49
62
|
splitChunks: {
|
|
50
63
|
cacheGroups: {
|
|
@@ -67,7 +80,7 @@ module.exports = () => {
|
|
|
67
80
|
plugins: [
|
|
68
81
|
// http://vuejs.github.io/vue-loader/en/workflow/production.html
|
|
69
82
|
new webpack.DefinePlugin({
|
|
70
|
-
'process.env.NODE_ENV': JSON.stringify(
|
|
83
|
+
'process.env.NODE_ENV': JSON.stringify(curEnvConfig.NODE_ENV) // vue-router中根据此变量判断执行环境
|
|
71
84
|
}),
|
|
72
85
|
new MiniCssExtractPlugin({
|
|
73
86
|
filename: utils.assetsPath('css/[name].[contenthash:8].css'),
|
|
@@ -94,9 +107,9 @@ module.exports = () => {
|
|
|
94
107
|
});
|
|
95
108
|
|
|
96
109
|
// 集成build配置中的构建入口
|
|
97
|
-
if (
|
|
110
|
+
if (curEnvConfig.entry) {
|
|
98
111
|
// 会覆盖config.webpack.entry的配置
|
|
99
|
-
webpackProdConfig.entry =
|
|
112
|
+
webpackProdConfig.entry = curEnvConfig.entry;
|
|
100
113
|
}
|
|
101
114
|
|
|
102
115
|
// 多页面支持能力
|
|
@@ -143,7 +156,7 @@ module.exports = () => {
|
|
|
143
156
|
patterns: [
|
|
144
157
|
{
|
|
145
158
|
from: resolve('public'), // 从这里拷贝
|
|
146
|
-
to:
|
|
159
|
+
to: curEnvConfig.assetsSubDirectory // 将根目录下的public内的资源复制到指定文件夹
|
|
147
160
|
}
|
|
148
161
|
]
|
|
149
162
|
})
|
|
@@ -151,10 +164,10 @@ module.exports = () => {
|
|
|
151
164
|
}
|
|
152
165
|
|
|
153
166
|
// 是否要进行压缩工作
|
|
154
|
-
if (
|
|
167
|
+
if (curEnvConfig.productionGzip) {
|
|
155
168
|
webpackProdConfig.plugins.push(
|
|
156
169
|
new CompressionWebpackPlugin({
|
|
157
|
-
test: new RegExp(`\\.(${
|
|
170
|
+
test: new RegExp(`\\.(${curEnvConfig.productionGzipExtensions.join('|')})$`),
|
|
158
171
|
filename: '[path].gz[query]',
|
|
159
172
|
algorithm: 'gzip',
|
|
160
173
|
threshold: 240,
|
|
@@ -163,7 +176,7 @@ module.exports = () => {
|
|
|
163
176
|
);
|
|
164
177
|
}
|
|
165
178
|
|
|
166
|
-
if (
|
|
179
|
+
if (curEnvConfig.bundleAnalyzerReport) {
|
|
167
180
|
webpackProdConfig.plugins.push(new BundleAnalyzerPlugin());
|
|
168
181
|
}
|
|
169
182
|
|