webpack.prod.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const merge = require('webpack-merge');
  2. const common = require('./webpack.common.config.js');
  3. const path = require('path');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  6. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  7. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  8. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  9. module.exports = merge(common, {
  10. module: {
  11. rules: [
  12. {
  13. test: /\.css$/,
  14. use: [
  15. MiniCssExtractPlugin.loader,
  16. 'css-loader'
  17. ]
  18. },
  19. {
  20. test: /\.less$/,
  21. use: [
  22. MiniCssExtractPlugin.loader,
  23. 'css-loader',
  24. 'less-loader'
  25. ]
  26. },
  27. {
  28. test: /\.(sass|scss)$/,
  29. use: [
  30. MiniCssExtractPlugin.loader,
  31. 'css-loader',
  32. 'sass-loader'
  33. ]
  34. },
  35. ]
  36. },
  37. optimization: {
  38. minimizer: [
  39. //new UglifyJsPlugin(),
  40. new OptimizeCssAssetsPlugin({
  41. assetNameRegExp: /\.css$/g,
  42. cssProcessor: require("cssnano"),
  43. cssProcessorPluginOptions: {
  44. preset: ['default', { discardComments: { removeAll: true } }]
  45. },
  46. canPrint: true
  47. })
  48. ],
  49. splitChunks: {
  50. chunks: 'all',
  51. minSize: 30000,
  52. maxSize: 0,
  53. minChunks: 1,
  54. cacheGroups: {
  55. framework: {
  56. test: "framework",
  57. name: "framework",
  58. enforce: true
  59. },
  60. vendors: {
  61. priority: -10,
  62. test: /node_modules/,
  63. name: "vendor",
  64. enforce: true,
  65. },
  66. }
  67. }
  68. },
  69. mode: 'production',
  70. output: {
  71. filename: 'nodejs/[name].[hash].bundle.js',
  72. },
  73. mode: 'development',
  74. devServer: {
  75. host: '127.0.0.1',
  76. allowedHosts: [
  77. 'cld2.com'
  78. ],
  79. proxy: { //设置代理
  80. "/cld2": {
  81. target: "http://cld2.com:7001",
  82. pathRewrite: { "^/cld2": "/cld2" },
  83. changeOrigin: true
  84. }
  85. },
  86. contentBase: path.resolve(__dirname, '../dist'),
  87. open: true,
  88. port: 9090,
  89. compress: true,
  90. hot: true,
  91. historyApiFallback: {
  92. rewrites: [
  93. {
  94. from: /^\/company/, to: '/',
  95. from: /^\/product\/lockStatistics/, to: '/product',
  96. from: /^\/product/, to: '/product',
  97. //客户相关
  98. from: /^\/contact/, to: '/contact',
  99. from: /^\/contact\/company/, to: '/contact',
  100. },
  101. ]
  102. }
  103. },
  104. plugins: [
  105. new HtmlWebpackPlugin({
  106. filename: 'index.html',
  107. template: 'public/index.html',
  108. chunks: ['workbench', 'framework'],
  109. // inject: 'body',
  110. // minify: {
  111. // removeComments: true,
  112. // collapseWhitespace: true,
  113. // },
  114. }),
  115. new MiniCssExtractPlugin({
  116. filename: 'nodecss/[name].[hash].css',
  117. chunkFilename: 'css/[id].[hash].css',
  118. }),
  119. //new CleanWebpackPlugin(),
  120. ]
  121. });