webpack.zhongdian.conf.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 UglifyJsPlugin = require("uglifyjs-webpack-plugin")
  13. process.env.NODE_ENV = 'production'
  14. const env = config.build.env
  15. var baseOption = {"project":"zhongdian"};
  16. const webpackConfig = merge(baseWebpackConfig(baseOption), {
  17. module: {
  18. rules: utils.styleLoaders({
  19. sourceMap: config.build.productionSourceMap,
  20. extract: true,
  21. project:baseOption.project
  22. })
  23. },
  24. devtool: config.build.productionSourceMap ? '#source-map' : false,
  25. output: {
  26. path: config.build.assetsRoot,
  27. filename: utils.assetsPath('js/[name].[chunkhash].js'),
  28. chunkFilename: utils.assetsPath('js/[id].[chunkhash].js'),
  29. publicPath: process.env.NODE_ENV === 'production'
  30. ? config.build.assetsPublicPath
  31. : config.dev.assetsPublicPath
  32. },
  33. plugins: [
  34. // http://vuejs.github.io/vue-loader/en/workflow/production.html
  35. new webpack.DefinePlugin({
  36. 'process.env': env,
  37. 'host.PROJECT': JSON.stringify(baseOption.project),
  38. // 'host.MQTT':JSON.stringify("111.235.156.143"),
  39. 'host.MQTT':JSON.stringify(""),
  40. }),
  41. // UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify
  42. // new webpack.optimize.UglifyJsPlugin({
  43. // compress: {
  44. // warnings: false
  45. // },
  46. // sourceMap: true
  47. // }),
  48. new UglifyJsPlugin({
  49. // 使用外部引入的新版本的js压缩工具
  50. parallel: true,
  51. uglifyOptions: {
  52. ie8: false,
  53. ecma: 6,
  54. warnings: false,
  55. mangle: true, // debug false
  56. output: {
  57. comments: false,
  58. beautify: false, // debug true
  59. },
  60. compress: {
  61. warnings: false, // 在UglifyJs删除没有用到的代码时不输出警告
  62. drop_console: true, //删除所有的 `console`语句,还可以兼容ie浏览器
  63. collapse_vars: true, // 内嵌定义了但是只用到一次的变量
  64. reduce_vars: true, // 提取出出现多次但是没有定义成变量去引用的静态值
  65. }
  66. }
  67. }),
  68. // extract css into its own file
  69. new ExtractTextPlugin({
  70. filename: utils.assetsPath('css/[name].[contenthash].css')
  71. }),
  72. // Compress extracted CSS. We are using this plugin so that possible
  73. // duplicated CSS from different components can be deduped.
  74. new OptimizeCSSPlugin({
  75. cssProcessorOptions: {
  76. safe: true
  77. }
  78. }),
  79. // generate dist index.html with correct asset hash for caching.
  80. // you can customize output by editing /index.html
  81. // see https://github.com/ampedandwired/html-webpack-plugin
  82. new HtmlWebpackPlugin({
  83. filename: config.build.index,
  84. template: 'index.html',
  85. inject: true,
  86. minify: {
  87. removeComments: true,
  88. collapseWhitespace: true,
  89. removeAttributeQuotes: true
  90. // more options:
  91. // https://github.com/kangax/html-minifier#options-quick-reference
  92. },
  93. // necessary to consistently work with multiple chunks via CommonsChunkPlugin
  94. chunksSortMode: 'dependency'
  95. }),
  96. // keep module.id stable when vender modules does not change
  97. new webpack.HashedModuleIdsPlugin(),
  98. // split vendor js into its own file
  99. new webpack.optimize.CommonsChunkPlugin({
  100. name: 'vendor',
  101. minChunks: function (module) {
  102. // any required modules inside node_modules are extracted to vendor
  103. return (
  104. module.resource &&
  105. /\.js$/.test(module.resource) &&
  106. module.resource.indexOf(
  107. path.join(__dirname, '../node_modules')
  108. ) === 0
  109. )
  110. }
  111. }),
  112. // extract webpack runtime and module manifest to its own file in order to
  113. // prevent vendor hash from being updated whenever app bundle is updated
  114. new webpack.optimize.CommonsChunkPlugin({
  115. name: 'manifest',
  116. chunks: ['vendor']
  117. }),
  118. // copy custom static assets
  119. new CopyWebpackPlugin([
  120. {
  121. from: path.resolve(__dirname, '../static'),
  122. to: config.build.assetsSubDirectory,
  123. ignore: ['.*']
  124. }
  125. ])
  126. ]
  127. })
  128. if (config.build.productionGzip) {
  129. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  130. webpackConfig.plugins.push(
  131. new CompressionWebpackPlugin({
  132. asset: '[path].gz[query]',
  133. algorithm: 'gzip',
  134. test: new RegExp(
  135. '\\.(' +
  136. config.build.productionGzipExtensions.join('|') +
  137. ')$'
  138. ),
  139. threshold: 10240,
  140. minRatio: 0.8
  141. })
  142. )
  143. }
  144. if (config.build.bundleAnalyzerReport) {
  145. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  146. webpackConfig.plugins.push(new BundleAnalyzerPlugin())
  147. }
  148. module.exports = webpackConfig