1
- const path = require ( ' path' ) ;
2
- const utils = require ( './utils' ) ;
3
- const webpack = require ( 'webpack' ) ;
4
- const chalk = require ( 'chalk' ) ;
5
- const CleanWebpackPlugin = require ( ' clean-webpack-plugin' ) ;
6
- const MiniCssExtractPlugin = require ( ' mini-css-extract-plugin' ) ;
7
- const OptimizeCSSAssetsPlugin = require ( ' optimize-css-assets-webpack-plugin' ) ;
1
+ const path = require ( " path" ) ;
2
+ const webpack = require ( "webpack" ) ;
3
+ const chalk = require ( "chalk" ) ;
4
+ const utils = require ( "./utils" ) ;
5
+ const { CleanWebpackPlugin } = require ( " clean-webpack-plugin" ) ;
6
+ const MiniCssExtractPlugin = require ( " mini-css-extract-plugin" ) ;
7
+ const OptimizeCSSAssetsPlugin = require ( " optimize-css-assets-webpack-plugin" ) ;
8
8
9
9
// dll文件存放的目录
10
- const dllPath = ' ../public/vendor' ;
10
+ const dllPath = " ../public/vendor" ;
11
11
12
12
const dllConf = {
13
- mode : ' production' ,
13
+ mode : " production" ,
14
14
entry : {
15
15
// 需要提取的库文件
16
- element : [ ' element-ui' , ' element-ui/lib/theme-chalk/index.css' ] ,
17
- axios : [ ' axios' ] ,
18
- vendor : [ ' vue' , ' vue-router' , ' vuex' , ' normalize.css' ]
16
+ element : [ " element-ui" , " element-ui/lib/theme-chalk/index.css" ] ,
17
+ axios : [ " axios" ] ,
18
+ vendor : [ " vue" , " vue-router" , " vuex" , " normalize.css" ]
19
19
} ,
20
20
module : {
21
21
rules : [
22
22
{
23
23
test : / \. ( w o f f 2 ? | e o t | t t f | o t f ) ( \? .* ) ? $ / ,
24
- loader : ' url-loader' ,
24
+ loader : " url-loader" ,
25
25
options : {
26
26
limit : 10000 ,
27
- name : ' [name].[hash:7].[ext]'
27
+ name : " [name].[hash:7].[ext]"
28
28
}
29
29
} ,
30
30
...utils . styleLoaders ( {
@@ -36,10 +36,10 @@ const dllConf = {
36
36
} ,
37
37
output : {
38
38
path : path . join ( __dirname , dllPath ) ,
39
- filename : ' [name].dll.js' ,
39
+ filename : " [name].dll.js" ,
40
40
// vendor.dll.js中暴露出的全局变量名
41
41
// 保持与 webpack.DllPlugin 中名称一致
42
- library : ' [name]_[hash]'
42
+ library : " [name]_[hash]"
43
43
} ,
44
44
optimization : {
45
45
minimizer : [
@@ -53,43 +53,45 @@ const dllConf = {
53
53
new CleanWebpackPlugin ( ) ,
54
54
// 设置环境变量
55
55
new webpack . DefinePlugin ( {
56
- ' process.env' : {
57
- NODE_ENV : 'production'
56
+ " process.env" : {
57
+ NODE_ENV : '" production" '
58
58
}
59
59
} ) ,
60
60
// extract css into its own file
61
61
new MiniCssExtractPlugin ( {
62
- filename : ' [name].dll.css'
62
+ filename : " [name].dll.css"
63
63
} ) ,
64
64
// manifest.json 描述动态链接库包含了哪些内容
65
65
new webpack . DllPlugin ( {
66
- path : path . join ( __dirname , dllPath , ' [name]-manifest.json' ) ,
66
+ path : path . join ( __dirname , dllPath , " [name]-manifest.json" ) ,
67
67
// 保持与 output.library 中名称一致
68
- name : ' [name]_[hash]' ,
68
+ name : " [name]_[hash]" ,
69
69
context : process . cwd ( )
70
70
} )
71
71
]
72
72
} ;
73
73
74
- webpack ( dllConf , function ( err , stats ) {
74
+ webpack ( dllConf , function ( err , stats ) {
75
75
if ( err ) throw err ;
76
- process . stdout . write ( stats . toString ( {
77
- colors : true ,
78
- modules : false ,
79
- children : false ,
80
- chunks : false ,
81
- chunkModules : false
82
- } ) + '\n\n' ) ;
76
+ process . stdout . write (
77
+ stats . toString ( {
78
+ colors : true ,
79
+ modules : false ,
80
+ children : false ,
81
+ chunks : false ,
82
+ chunkModules : false
83
+ } ) + "\n\n"
84
+ ) ;
83
85
84
86
if ( stats . hasErrors ( ) ) {
85
87
const info = stats . toJson ( ) ;
86
- console . error ( '\n' ) ;
87
- console . error ( chalk . magenta ( ' 编译打包出错了 ~~~~(>_<)~~~~ \n' ) ) ;
88
- console . error ( chalk . magenta ( ' 具体错误信息如下 \n' ) ) ;
88
+ console . error ( "\n" ) ;
89
+ console . error ( chalk . magenta ( " 编译打包出错了 ~~~~(>_<)~~~~ \n" ) ) ;
90
+ console . error ( chalk . magenta ( " 具体错误信息如下 \n" ) ) ;
89
91
console . error ( chalk . red ( `${ info . errors } .\n` ) ) ;
90
- console . log ( chalk . red ( ' Build failed with errors.\n' ) ) ;
92
+ console . log ( chalk . red ( " Build failed with errors.\n" ) ) ;
91
93
process . exit ( 1 ) ;
92
94
}
93
95
94
- console . log ( chalk . cyan ( ' Build dll complete.\n' ) ) ;
96
+ console . log ( chalk . cyan ( " Build dll complete.\n" ) ) ;
95
97
} ) ;
0 commit comments