git ssb

0+

dangerousbeans / etherstreams



Tree: 5b2e405d30a0a28a8d6b43dd4ec8b16cdba28cf8

Files: 5b2e405d30a0a28a8d6b43dd4ec8b16cdba28cf8 / build / webpack.prod.conf.js

3992 bytesRaw
1var path = require('path')
2var utils = require('./utils')
3var webpack = require('webpack')
4var config = require('../config')
5var merge = require('webpack-merge')
6var baseWebpackConfig = require('./webpack.base.conf')
7var CopyWebpackPlugin = require('copy-webpack-plugin')
8var HtmlWebpackPlugin = require('html-webpack-plugin')
9var ExtractTextPlugin = require('extract-text-webpack-plugin')
10var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
11var UglifyESPlugin = require('uglifyjs-webpack-plugin')
12
13
14var env = process.env.NODE_ENV === 'testing'
15 ? require('../config/test.env')
16 : config.build.env
17
18var webpackConfig = merge(baseWebpackConfig, {
19 module: {
20 rules: utils.styleLoaders({
21 sourceMap: config.build.productionSourceMap,
22 extract: true
23 })
24 },
25 devtool: config.build.productionSourceMap ? '#source-map' : false,
26 output: {
27 path: config.build.assetsRoot,
28 filename: utils.assetsPath('js/[name].[chunkhash].js'),
29 chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
30 },
31 plugins: [
32 // http://vuejs.github.io/vue-loader/en/workflow/production.html
33 new webpack.DefinePlugin({
34 'process.env': env
35 }),
36 // minify with dead-code elimination
37 new UglifyESPlugin({}),
38 // extract css into its own file
39 new ExtractTextPlugin({
40 filename: utils.assetsPath('css/[name].[contenthash].css')
41 }),
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: {
46 safe: true
47 }
48 }),
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: process.env.NODE_ENV === 'testing'
54 ? 'index.html'
55 : config.build.index,
56 template: 'index.html',
57 inject: true,
58 minify: {
59 removeComments: true,
60 collapseWhitespace: true,
61 removeAttributeQuotes: true
62 // more options:
63 // https://github.com/kangax/html-minifier#options-quick-reference
64 },
65 // necessary to consistently work with multiple chunks via CommonsChunkPlugin
66 chunksSortMode: 'dependency'
67 }),
68 // keep module.id stable when vender modules does not change
69 new webpack.HashedModuleIdsPlugin(),
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
101if (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
119if (config.build.bundleAnalyzerReport) {
120 var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
121 webpackConfig.plugins.push(new BundleAnalyzerPlugin())
122}
123
124module.exports = webpackConfig
125

Built with git-ssb-web