webpack.prod.conf.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const webpack = require('webpack')
  5. const config = require('../config')
  6. const merge = require('webpack-merge')
  7. const baseWebpackConfig = require('./webpack.base.conf')
  8. const CopyWebpackPlugin = require('copy-webpack-plugin')
  9. const HtmlWebpackPlugin = require('html-webpack-plugin')
  10. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  11. const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
  12. const env = config.build.env
  13. var baseOption = {"project":"ebei"};
  14. const webpackConfig = merge(baseWebpackConfig(baseOption), {
  15. module: {
  16. rules: utils.styleLoaders({
  17. sourceMap: config.build.productionSourceMap,
  18. extract: true,
  19. project:baseOption.project
  20. })
  21. },
  22. devtool: config.build.productionSourceMap ? '#source-map' : false,
  23. output: {
  24. path: config.build.assetsRoot,
  25. filename: utils.assetsPath('js/[name].[chunkhash].js'),
  26. chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
  27. },
  28. plugins: [
  29. // http://vuejs.github.io/vue-loader/en/workflow/production.html
  30. new webpack.DefinePlugin({
  31. 'process.env': env,
  32. 'host.PROJECT':JSON.stringify(baseOption.project),
  33. 'host.LOGINPATH': JSON.stringify('') //统一登录路径
  34. }),
  35. // UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify
  36. // new webpack.optimize.UglifyJsPlugin({
  37. // compress: {
  38. // warnings: false
  39. // },
  40. // sourceMap: true
  41. // }),
  42. // extract css into its own file
  43. new ExtractTextPlugin({
  44. filename: utils.assetsPath('css/[name].[contenthash].css')
  45. }),
  46. // Compress extracted CSS. We are using this plugin so that possible
  47. // duplicated CSS from different components can be deduped.
  48. new OptimizeCSSPlugin({
  49. cssProcessorOptions: {
  50. safe: true
  51. }
  52. }),
  53. // generate dist index.html with correct asset hash for caching.
  54. // you can customize output by editing /index.html
  55. // see https://github.com/ampedandwired/html-webpack-plugin
  56. new HtmlWebpackPlugin({
  57. filename: 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) {
  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. if (config.build.productionGzip) {
  103. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  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. if (config.build.bundleAnalyzerReport) {
  119. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  120. webpackConfig.plugins.push(new BundleAnalyzerPlugin())
  121. }
  122. module.exports = webpackConfig