github.com/titpetric/pendulum@v0.1.180207-1512.0.20180514135826-1f399445df57/front/src/build/webpack.prod.conf.js (about) 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') 11 12 var env = process.env.NODE_ENV === 'testing' 13 ? require('../config/test.env') 14 : config.build.env 15 16 var webpackConfig = merge(baseWebpackConfig, { 17 module: { 18 rules: utils.styleLoaders({ 19 sourceMap: config.build.productionSourceMap, 20 extract: true 21 }) 22 }, 23 devtool: config.build.productionSourceMap ? '#source-map' : false, 24 output: { 25 path: config.build.assetsRoot, 26 filename: utils.assetsPath('js/[name].[chunkhash].js'), 27 chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 28 }, 29 plugins: [ 30 // http://vuejs.github.io/vue-loader/en/workflow/production.html 31 new webpack.DefinePlugin({ 32 'process.env': env 33 }), 34 new webpack.optimize.UglifyJsPlugin({ 35 compress: { 36 warnings: false 37 }, 38 sourceMap: config.build.productionSourceMap 39 }), 40 // extract css into its own file 41 new ExtractTextPlugin({ 42 filename: utils.assetsPath('css/[name].[contenthash].css') 43 }), 44 // Compress extracted CSS. We are using this plugin so that possible 45 // duplicated CSS from different components can be deduped. 46 new OptimizeCSSPlugin({ 47 cssProcessorOptions: { 48 safe: true 49 } 50 }), 51 // generate dist index.html with correct asset hash for caching. 52 // you can customize output by editing /index.html 53 // see https://github.com/ampedandwired/html-webpack-plugin 54 new HtmlWebpackPlugin({ 55 filename: process.env.NODE_ENV === 'testing' 56 ? 'index.html' 57 : config.build.index, 58 template: 'index.html', 59 inject: true, 60 minify: { 61 removeComments: true, 62 collapseWhitespace: true, 63 removeAttributeQuotes: true 64 // more options: 65 // https://github.com/kangax/html-minifier#options-quick-reference 66 }, 67 // necessary to consistently work with multiple chunks via CommonsChunkPlugin 68 chunksSortMode: 'dependency' 69 }), 70 // split vendor js into its own file 71 new webpack.optimize.CommonsChunkPlugin({ 72 name: 'vendor', 73 minChunks: function (module, count) { 74 // any required modules inside node_modules are extracted to vendor 75 return ( 76 module.resource && 77 /\.js$/.test(module.resource) && 78 module.resource.indexOf( 79 path.join(__dirname, '../node_modules') 80 ) === 0 81 ) 82 } 83 }), 84 // extract webpack runtime and module manifest to its own file in order to 85 // prevent vendor hash from being updated whenever app bundle is updated 86 new webpack.optimize.CommonsChunkPlugin({ 87 name: 'manifest', 88 chunks: ['vendor'] 89 }), 90 // copy custom static assets 91 new CopyWebpackPlugin([ 92 { 93 from: path.resolve(__dirname, '../static'), 94 to: config.build.assetsSubDirectory, 95 ignore: ['.*'] 96 } 97 ]) 98 ] 99 }) 100 101 if (config.build.productionGzip) { 102 var CompressionWebpackPlugin = require('compression-webpack-plugin') 103 104 webpackConfig.plugins.push( 105 new CompressionWebpackPlugin({ 106 asset: '[path].gz[query]', 107 algorithm: 'gzip', 108 test: new RegExp( 109 '\\.(' + 110 config.build.productionGzipExtensions.join('|') + 111 ')$' 112 ), 113 threshold: 10240, 114 minRatio: 0.8 115 }) 116 ) 117 } 118 119 if (config.build.bundleAnalyzerReport) { 120 var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 121 webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 122 } 123 124 module.exports = webpackConfig