webpack.prod.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. publicPath: 'http://cld2.com:9090/',
  72. filename: 'nodejs/[name].[hash].bundle.js',
  73. },
  74. mode: 'development',
  75. devServer: {
  76. host: '127.0.0.1',
  77. allowedHosts: [
  78. 'cld2.com'
  79. ],
  80. proxy: { //设置代理
  81. "/cld2": {
  82. target: "http://192.168.1.26:7001/",
  83. pathRewrite: { "^/cld2": "/cld2" },
  84. changeOrigin: true
  85. }
  86. },
  87. contentBase: path.resolve(__dirname, '../dist'),
  88. open: true,
  89. port: 9090,
  90. compress: true,
  91. hot: true,
  92. historyApiFallback: {
  93. rewrites: [
  94. {
  95. // from: /\/hr/, to: '/hr',
  96. // from: /\/hr\/indof/, to: '/hr',
  97. from: '/contact', to: '/contact',
  98. //from: /^\/contact\/company/, to: '/contact',
  99. //from: /^\/product/, to: '/product',
  100. //from: /^\/product\/lockCount/, to: '/product',
  101. //from: /product/, to: '/product',
  102. //from: /product\/lockCount/, to: '/product',
  103. // from: /^\/wo\/wo/, to: '/',
  104. // from: /^\/contact/, to: '/contact',
  105. // from: /^\/contact\/company/, to: '/contact',
  106. // from: /^\/product/, to: '/product',
  107. // from: /^\/product\/company/, to: '/product',
  108. // from: /^\/product\/hr/, to: '/hr',
  109. },
  110. {
  111. from: '/product', to: '/product',
  112. },
  113. {
  114. from: '/login', to: '/login',
  115. },
  116. ]
  117. }
  118. },
  119. plugins: [
  120. new HtmlWebpackPlugin({
  121. template: 'public/index.html',
  122. filename: 'index.html',
  123. chunks: ['workbench', 'framework'],
  124. // inject: 'body',
  125. // minify: {
  126. // removeComments: true,
  127. // collapseWhitespace: true,
  128. // },
  129. }),
  130. new MiniCssExtractPlugin({
  131. filename: 'nodecss/[name].[hash].css',
  132. chunkFilename: 'css/[id].[hash].css',
  133. }),
  134. //new CleanWebpackPlugin(),
  135. ]
  136. });