Merge the latest version of Speedometer 2.0 to browserbench.org against at r222534.
[WebKit-https.git] / Websites / browserbench.org / Speedometer2.0 / resources / todomvc / architecture-examples / vuejs-cli / build / webpack.prod.conf.js
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: true
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     // keep module.id stable when vender modules does not change
71     new webpack.HashedModuleIdsPlugin(),
72     // split vendor js into its own file
73     new webpack.optimize.CommonsChunkPlugin({
74       name: 'vendor',
75       minChunks: function (module, count) {
76         // any required modules inside node_modules are extracted to vendor
77         return (
78           module.resource &&
79           /\.js$/.test(module.resource) &&
80           module.resource.indexOf(
81             path.join(__dirname, '../node_modules')
82           ) === 0
83         )
84       }
85     }),
86     // extract webpack runtime and module manifest to its own file in order to
87     // prevent vendor hash from being updated whenever app bundle is updated
88     new webpack.optimize.CommonsChunkPlugin({
89       name: 'manifest',
90       chunks: ['vendor']
91     }),
92     // copy custom static assets
93     new CopyWebpackPlugin([
94       {
95         from: path.resolve(__dirname, '../static'),
96         to: config.build.assetsSubDirectory,
97         ignore: ['.*']
98       }
99     ])
100   ]
101 })
102
103 if (config.build.productionGzip) {
104   var CompressionWebpackPlugin = require('compression-webpack-plugin')
105
106   webpackConfig.plugins.push(
107     new CompressionWebpackPlugin({
108       asset: '[path].gz[query]',
109       algorithm: 'gzip',
110       test: new RegExp(
111         '\\.(' +
112         config.build.productionGzipExtensions.join('|') +
113         ')$'
114       ),
115       threshold: 10240,
116       minRatio: 0.8
117     })
118   )
119 }
120
121 if (config.build.bundleAnalyzerReport) {
122   var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
123   webpackConfig.plugins.push(new BundleAnalyzerPlugin())
124 }
125
126 module.exports = webpackConfig