微小悟公众号管理系统

webpack.prod.conf.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. var env = process.env.NODE_ENV === 'testing'
  12. ? require('../config/test.env')
  13. : config.build.env
  14. var webpackConfig = merge(baseWebpackConfig, {
  15. module: {
  16. rules: utils.styleLoaders({
  17. sourceMap: config.build.productionSourceMap,
  18. extract: true
  19. })
  20. },
  21. devtool: config.build.productionSourceMap ? '#source-map' : false,
  22. output: {
  23. // publicPath: './',
  24. path: config.build.assetsRoot,
  25. filename: '[name].[contenthash].js',
  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': Object.assign({}, config.dev.env, {API_ENV: '"' + process.env.API_ENV.trim() + '"'})
  33. }),
  34. new webpack.optimize.UglifyJsPlugin({
  35. compress: {
  36. warnings: false
  37. },
  38. sourceMap: false
  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. if (config.build.productionGzip) {
  101. var CompressionWebpackPlugin = require('compression-webpack-plugin')
  102. webpackConfig.plugins.push(
  103. new CompressionWebpackPlugin({
  104. asset: '[path].gz[query]',
  105. algorithm: 'gzip',
  106. test: new RegExp(
  107. '\\.(' +
  108. config.build.productionGzipExtensions.join('|') +
  109. ')$'
  110. ),
  111. threshold: 10240,
  112. minRatio: 0.8
  113. })
  114. )
  115. }
  116. if (config.build.bundleAnalyzerReport) {
  117. var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  118. webpackConfig.plugins.push(new BundleAnalyzerPlugin())
  119. }
  120. module.exports = webpackConfig