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')
12 var env
= config
.build
.env
14 var webpackConfig
= merge(baseWebpackConfig
, {
16 rules
: utils
.styleLoaders({
17 sourceMap
: config
.build
.productionSourceMap
,
21 devtool
: config
.build
.productionSourceMap
? '#source-map' : false,
23 path
: config
.build
.assetsRoot
,
24 filename
: utils
.assetsPath('js/[name].[chunkhash].js'),
25 chunkFilename
: utils
.assetsPath('js/[id].[chunkhash].js')
28 // http://vuejs.github.io/vue-loader/en/workflow/production.html
29 new webpack
.DefinePlugin({
32 new webpack
.optimize
.UglifyJsPlugin({
38 // extract css into its own file
39 new ExtractTextPlugin({
40 filename
: utils
.assetsPath('css/[name].[contenthash].css')
42 // Compress extracted CSS. We are using this plugin so that possible
43 // duplicated CSS from different components can be deduped.
44 new OptimizeCSSPlugin({
45 cssProcessorOptions
: {
49 // generate dist index.html with correct asset hash for caching.
50 // you can customize output by editing /index.html
51 // see https://github.com/ampedandwired/html-webpack-plugin
52 new HtmlWebpackPlugin({
53 filename
: config
.build
.index
,
54 template
: 'index.html',
58 collapseWhitespace
: true,
59 removeAttributeQuotes
: true
61 // https://github.com/kangax/html-minifier#options-quick-reference
63 // necessary to consistently work with multiple chunks via CommonsChunkPlugin
64 chunksSortMode
: 'dependency'
66 // split vendor js into its own file
67 new webpack
.optimize
.CommonsChunkPlugin({
69 minChunks: function (module
, count
) {
70 // any required modules inside node_modules are extracted to vendor
73 /\.js$/.test(module
.resource
) &&
74 module
.resource
.indexOf(
75 path
.join(__dirname
, '../node_modules')
80 // extract webpack runtime and module manifest to its own file in order to
81 // prevent vendor hash from being updated whenever app bundle is updated
82 new webpack
.optimize
.CommonsChunkPlugin({
86 // copy custom static assets
87 new CopyWebpackPlugin([
89 from: path
.resolve(__dirname
, '../static'),
90 to
: config
.build
.assetsSubDirectory
,
97 if (config
.build
.productionGzip
) {
98 var CompressionWebpackPlugin
= require('compression-webpack-plugin')
100 webpackConfig
.plugins
.push(
101 new CompressionWebpackPlugin({
102 asset
: '[path].gz[query]',
106 config
.build
.productionGzipExtensions
.join('|') +
115 if (config
.build
.bundleAnalyzerReport
) {
116 var BundleAnalyzerPlugin
= require('webpack-bundle-analyzer').BundleAnalyzerPlugin
117 webpackConfig
.plugins
.push(new BundleAnalyzerPlugin())
120 module
.exports
= webpackConfig