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+ 'use strict'
2+ const path = require ( 'path' )
3+ const utils = require ( './utils' )
4+ const webpack = require ( 'webpack' )
5+ const config = require ( '../config' )
6+ const merge = require ( 'webpack-merge' )
7+ const baseWebpackConfig = require ( './webpack.base.conf' )
8+ const CopyWebpackPlugin = require ( 'copy-webpack-plugin' )
9+ const HtmlWebpackPlugin = require ( 'html-webpack-plugin' )
10+ const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' )
11+ const OptimizeCSSPlugin = require ( 'optimize-css-assets-webpack-plugin' )
12+ const UglifyJsPlugin = require ( 'uglifyjs-webpack-plugin' )
1113
12- var env = config . build . env
14+ const env = require ( '../config/prod. env' )
1315
14- var webpackConfig = merge ( baseWebpackConfig , {
16+ const webpackConfig = merge ( baseWebpackConfig , {
1517 module : {
1618 rules : utils . styleLoaders ( {
1719 sourceMap : config . build . productionSourceMap ,
18- extract : true
20+ extract : true ,
21+ usePostCSS : true
1922 } )
2023 } ,
21- devtool : config . build . productionSourceMap ? '#source-map' : false ,
24+ devtool : config . build . productionSourceMap ? config . build . devtool : false ,
2225 output : {
2326 path : config . build . assetsRoot ,
2427 filename : utils . assetsPath ( 'js/[name].[chunkhash].js' ) ,
@@ -29,22 +32,30 @@ var webpackConfig = merge(baseWebpackConfig, {
2932 new webpack . DefinePlugin ( {
3033 'process.env' : env
3134 } ) ,
32- new webpack . optimize . UglifyJsPlugin ( {
33- compress : {
34- warnings : false
35+ new UglifyJsPlugin ( {
36+ uglifyOptions : {
37+ compress : {
38+ warnings : false
39+ }
3540 } ,
36- sourceMap : true
41+ sourceMap : config . build . productionSourceMap ,
42+ parallel : true
3743 } ) ,
3844 // extract css into its own file
3945 new ExtractTextPlugin ( {
40- filename : utils . assetsPath ( 'css/[name].[contenthash].css' )
46+ filename : utils . assetsPath ( 'css/[name].[contenthash].css' ) ,
47+ // Setting the following option to `false` will not extract CSS from codesplit chunks.
48+ // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
49+ // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
50+ // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
51+ allChunks : true ,
4152 } ) ,
4253 // Compress extracted CSS. We are using this plugin so that possible
4354 // duplicated CSS from different components can be deduped.
4455 new OptimizeCSSPlugin ( {
45- cssProcessorOptions : {
46- safe : true
47- }
56+ cssProcessorOptions : config . build . productionSourceMap
57+ ? { safe : true , map : { inline : false } }
58+ : { safe : true }
4859 } ) ,
4960 // generate dist index.html with correct asset hash for caching.
5061 // you can customize output by editing /index.html
@@ -63,14 +74,18 @@ var webpackConfig = merge(baseWebpackConfig, {
6374 // necessary to consistently work with multiple chunks via CommonsChunkPlugin
6475 chunksSortMode : 'dependency'
6576 } ) ,
77+ // keep module.id stable when vendor modules does not change
78+ new webpack . HashedModuleIdsPlugin ( ) ,
79+ // enable scope hoisting
80+ new webpack . optimize . ModuleConcatenationPlugin ( ) ,
6681 // split your library css/js into separate files
6782 new webpack . optimize . CommonsChunkPlugin ( {
6883 name : 'v-chacheli'
6984 } ) ,
7085 // split vendor js into its own file
7186 new webpack . optimize . CommonsChunkPlugin ( {
7287 name : 'vendor' ,
73- minChunks : function ( module , count ) {
88+ minChunks ( module ) {
7489 // any required modules inside node_modules are extracted to vendor
7590 return (
7691 module . resource &&
@@ -99,7 +114,7 @@ var webpackConfig = merge(baseWebpackConfig, {
99114} )
100115
101116if ( config . build . productionGzip ) {
102- var CompressionWebpackPlugin = require ( 'compression-webpack-plugin' )
117+ const CompressionWebpackPlugin = require ( 'compression-webpack-plugin' )
103118
104119 webpackConfig . plugins . push (
105120 new CompressionWebpackPlugin ( {
@@ -117,7 +132,7 @@ if (config.build.productionGzip) {
117132}
118133
119134if ( config . build . bundleAnalyzerReport ) {
120- var BundleAnalyzerPlugin = require ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin
135+ const BundleAnalyzerPlugin = require ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin
121136 webpackConfig . plugins . push ( new BundleAnalyzerPlugin ( ) )
122137}
123138
0 commit comments