跳板机管理web端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.0 KiB

8 years ago
  1. var path = require('path')
  2. var config = require('../config')
  3. var utils = require('./utils')
  4. var webpack = require('webpack')
  5. var merge = require('webpack-merge')
  6. var baseWebpackConfig = require('./webpack.base.conf')
  7. var ExtractTextPlugin = require('extract-text-webpack-plugin')
  8. var HtmlWebpackPlugin = require('html-webpack-plugin')
  9. var env = config.build.env
  10. var webpackConfig = merge(baseWebpackConfig, {
  11. module: {
  12. loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true })
  13. },
  14. devtool: config.build.productionSourceMap ? '#source-map' : false,
  15. output: {
  16. path: config.build.assetsRoot,
  17. filename: utils.assetsPath('js/[name].[chunkhash].js'),
  18. chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
  19. },
  20. vue: {
  21. loaders: utils.cssLoaders({
  22. sourceMap: config.build.productionSourceMap,
  23. extract: true
  24. })
  25. },
  26. plugins: [
  27. // http://vuejs.github.io/vue-loader/en/workflow/production.html
  28. new webpack.DefinePlugin({
  29. 'process.env': env
  30. }),
  31. new webpack.optimize.UglifyJsPlugin({
  32. compress: {
  33. warnings: false
  34. }
  35. }),
  36. new webpack.optimize.OccurenceOrderPlugin(),
  37. // extract css into its own file
  38. new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')),
  39. // generate dist index.html with correct asset hash for caching.
  40. // you can customize output by editing /index.html
  41. // see https://github.com/ampedandwired/html-webpack-plugin
  42. new HtmlWebpackPlugin({
  43. filename: config.build.index,
  44. template: 'index.html',
  45. inject: true,
  46. minify: {
  47. removeComments: true,
  48. collapseWhitespace: true,
  49. removeAttributeQuotes: true
  50. // more options:
  51. // https://github.com/kangax/html-minifier#options-quick-reference
  52. },
  53. // necessary to consistently work with multiple chunks via CommonsChunkPlugin
  54. chunksSortMode: 'dependency'
  55. }),
  56. // split vendor js into its own file
  57. new webpack.optimize.CommonsChunkPlugin({
  58. name: 'vendor',
  59. minChunks: function (module, count) {
  60. // any required modules inside node_modules are extracted to vendor
  61. return (
  62. module.resource &&
  63. /\.js$/.test(module.resource) &&
  64. module.resource.indexOf(
  65. path.join(__dirname, '../node_modules')
  66. ) === 0
  67. )
  68. }
  69. }),
  70. // extract webpack runtime and module manifest to its own file in order to
  71. // prevent vendor hash from being updated whenever app bundle is updated
  72. new webpack.optimize.CommonsChunkPlugin({
  73. name: 'manifest',
  74. chunks: ['vendor']
  75. })
  76. ]
  77. })
  78. if (config.build.productionGzip) {
  79. var CompressionWebpackPlugin = require('compression-webpack-plugin')
  80. webpackConfig.plugins.push(
  81. new CompressionWebpackPlugin({
  82. asset: '[path].gz[query]',
  83. algorithm: 'gzip',
  84. test: new RegExp(
  85. '\\.(' +
  86. config.build.productionGzipExtensions.join('|') +
  87. ')$'
  88. ),
  89. threshold: 10240,
  90. minRatio: 0.8
  91. })
  92. )
  93. }
  94. module.exports = webpackConfig