1
- var path = require ( 'path' )
2
- var utils = require ( './utils' )
3
- var webpack = require ( 'webpack' )
4
- var config = require ( '../config' )
5
- var merge = require ( 'webpack-merge' )
6
- var baseWebpackConfig = require ( './webpack.base.conf' )
7
- var CopyWebpackPlugin = require ( 'copy-webpack-plugin' )
8
- var HtmlWebpackPlugin = require ( 'html-webpack-plugin' )
9
- var ExtractTextPlugin = require ( 'extract-text-webpack-plugin' )
10
- var OptimizeCSSPlugin = require ( 'optimize-css-assets-webpack-plugin' )
1
+ const path = require ( 'path' ) ;
2
+ const utils = require ( './utils' ) ;
3
+ const webpack = require ( 'webpack' ) ;
4
+ const config = require ( '../config' ) ;
5
+ const merge = require ( 'webpack-merge' ) ;
6
+ const baseWebpackConfig = require ( './webpack.base.conf' ) ;
7
+ const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
8
+ const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
9
+ const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
10
+ const OptimizeCSSPlugin = require ( 'optimize-css-assets-webpack-plugin' ) ;
11
11
12
- var env = process . env . NODE_ENV === 'testing'
12
+ const env = process . env . NODE_ENV === 'testing'
13
13
? require ( '../config/test.env' )
14
- : config . build . env
14
+ : config . build . env ;
15
15
16
- var webpackConfig = merge ( baseWebpackConfig , {
16
+ function resolve ( dir ) {
17
+ return path . join ( __dirname , '..' , dir ) ;
18
+ }
19
+
20
+ const webpackConfig = merge ( baseWebpackConfig , {
17
21
module : {
18
22
rules : utils . styleLoaders ( {
19
23
sourceMap : config . build . productionSourceMap ,
20
- extract : true
21
- } )
24
+ extract : true ,
25
+ } ) . concat (
26
+ {
27
+ test : / \. ( j s | v u e ) $ / ,
28
+ loader : 'eslint-loader' ,
29
+ enforce : 'pre' ,
30
+ include : [ resolve ( 'src' ) , resolve ( 'test' ) ] ,
31
+ options : {
32
+ formatter : require ( 'eslint-friendly-formatter' ) ,
33
+ } ,
34
+ } ,
35
+ ) ,
22
36
} ,
23
37
devtool : config . build . productionSourceMap ? '#source-map' : false ,
24
38
output : {
25
39
path : config . build . assetsRoot ,
26
40
publicPath : '/' ,
27
41
filename : utils . assetsPath ( 'js/[name].[chunkhash].js' ) ,
28
- chunkFilename : utils . assetsPath ( 'js/[id].[chunkhash].js' )
42
+ chunkFilename : utils . assetsPath ( 'js/[id].[chunkhash].js' ) ,
29
43
} ,
30
44
plugins : [
31
45
// http://vuejs.github.io/vue-loader/en/workflow/production.html
32
46
new webpack . DefinePlugin ( {
33
- 'process.env' : env
47
+ 'process.env' : env ,
34
48
} ) ,
35
49
new webpack . optimize . UglifyJsPlugin ( {
36
50
compress : {
37
- warnings : false
51
+ warnings : false ,
38
52
} ,
39
- sourceMap : true
53
+ sourceMap : true ,
40
54
} ) ,
41
55
// extract css into its own file
42
56
new ExtractTextPlugin ( {
43
- filename : utils . assetsPath ( 'css/[name].[contenthash].css' )
57
+ filename : utils . assetsPath ( 'css/[name].[contenthash].css' ) ,
44
58
} ) ,
45
59
// Compress extracted CSS. We are using this plugin so that possible
46
60
// duplicated CSS from different components can be deduped.
47
61
new OptimizeCSSPlugin ( {
48
62
cssProcessorOptions : {
49
- safe : true
50
- }
63
+ safe : true ,
64
+ } ,
51
65
} ) ,
52
66
// generate dist index.html with correct asset hash for caching.
53
67
// you can customize output by editing /index.html
@@ -60,12 +74,12 @@ var webpackConfig = merge(baseWebpackConfig, {
60
74
inject : true ,
61
75
minify : {
62
76
removeComments : true ,
63
- collapseWhitespace : true
77
+ collapseWhitespace : true ,
64
78
// more options:
65
79
// https://github.com/kangax/html-minifier#options-quick-reference
66
80
} ,
67
81
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
68
- chunksSortMode : 'dependency'
82
+ chunksSortMode : 'dependency' ,
69
83
} ) ,
70
84
// generate dist opengraph.hbs with correct asset hash for caching.
71
85
// Used when requesting pages which should have OpenGraph meta tags on request
@@ -76,65 +90,65 @@ var webpackConfig = merge(baseWebpackConfig, {
76
90
inject : true ,
77
91
minify : {
78
92
removeComments : true ,
79
- collapseWhitespace : true
93
+ collapseWhitespace : true ,
80
94
// more options:
81
95
// https://github.com/kangax/html-minifier#options-quick-reference
82
96
} ,
83
97
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
84
- chunksSortMode : 'dependency'
98
+ chunksSortMode : 'dependency' ,
85
99
} ) ,
86
100
// split vendor js into its own file
87
101
new webpack . optimize . CommonsChunkPlugin ( {
88
102
name : 'vendor' ,
89
- minChunks : function ( module , count ) {
103
+ minChunks ( module , count ) {
90
104
// any required modules inside node_modules are extracted to vendor
91
105
return (
92
106
module . resource &&
93
107
/ \. j s $ / . test ( module . resource ) &&
94
108
module . resource . indexOf (
95
- path . join ( __dirname , '../node_modules' )
109
+ path . join ( __dirname , '../node_modules' ) ,
96
110
) === 0
97
- )
98
- }
111
+ ) ;
112
+ } ,
99
113
} ) ,
100
114
// extract webpack runtime and module manifest to its own file in order to
101
115
// prevent vendor hash from being updated whenever app bundle is updated
102
116
new webpack . optimize . CommonsChunkPlugin ( {
103
117
name : 'manifest' ,
104
- chunks : [ 'vendor' ]
118
+ chunks : [ 'vendor' ] ,
105
119
} ) ,
106
120
// copy custom static assets
107
121
new CopyWebpackPlugin ( [
108
122
{
109
123
from : path . resolve ( __dirname , '../static' ) ,
110
124
to : config . build . assetsSubDirectory ,
111
- ignore : [ '.*' ]
112
- }
113
- ] )
114
- ]
115
- } )
125
+ ignore : [ '.*' ] ,
126
+ } ,
127
+ ] ) ,
128
+ ] ,
129
+ } ) ;
116
130
117
131
if ( config . build . productionGzip ) {
118
- var CompressionWebpackPlugin = require ( 'compression-webpack-plugin' )
132
+ const CompressionWebpackPlugin = require ( 'compression-webpack-plugin' ) ;
119
133
120
134
webpackConfig . plugins . push (
121
135
new CompressionWebpackPlugin ( {
122
136
asset : '[path].gz[query]' ,
123
137
algorithm : 'gzip' ,
124
138
test : new RegExp (
125
- ' \\.(' +
126
- config . build . productionGzipExtensions . join ( '|' ) +
127
- ')$'
139
+ ` \\.(${
140
+ config . build . productionGzipExtensions . join ( '|' )
141
+ } )$` ,
128
142
) ,
129
143
threshold : 10240 ,
130
- minRatio : 0.8
131
- } )
132
- )
144
+ minRatio : 0.8 ,
145
+ } ) ,
146
+ ) ;
133
147
}
134
148
135
149
if ( config . build . bundleAnalyzerReport ) {
136
- var BundleAnalyzerPlugin = require ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin
137
- webpackConfig . plugins . push ( new BundleAnalyzerPlugin ( ) )
150
+ const BundleAnalyzerPlugin = require ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin ;
151
+ webpackConfig . plugins . push ( new BundleAnalyzerPlugin ( ) ) ;
138
152
}
139
153
140
- module . exports = webpackConfig
154
+ module . exports = webpackConfig ;
0 commit comments