webpack.prod.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. exclude: /\.module\.less$/,
  22. use: [
  23. MiniCssExtractPlugin.loader,
  24. 'css-loader',
  25. 'less-loader'
  26. ]
  27. },
  28. {
  29. test: /\.module\.less$/,
  30. use: [
  31. 'style-loader',
  32. {
  33. loader: 'css-loader',
  34. options: {
  35. modules: true
  36. }
  37. },
  38. 'less-loader'
  39. ]
  40. },
  41. {
  42. test: /\.(sass|scss)$/,
  43. use: [
  44. MiniCssExtractPlugin.loader,
  45. 'css-loader',
  46. 'sass-loader'
  47. ]
  48. },
  49. ]
  50. },
  51. optimization: {
  52. minimizer: [
  53. //new UglifyJsPlugin(),
  54. new OptimizeCssAssetsPlugin({
  55. assetNameRegExp: /\.css$/g,
  56. cssProcessor: require("cssnano"),
  57. cssProcessorPluginOptions: {
  58. preset: ['default', { discardComments: { removeAll: true } }]
  59. },
  60. canPrint: true
  61. })
  62. ],
  63. splitChunks: {
  64. chunks: 'all',
  65. minSize: 30000,
  66. maxSize: 0,
  67. minChunks: 1,
  68. cacheGroups: {
  69. framework: {
  70. test: "framework",
  71. name: "framework",
  72. enforce: true
  73. },
  74. vendors: {
  75. priority: -10,
  76. test: /node_modules/,
  77. name: "vendor",
  78. enforce: true,
  79. },
  80. }
  81. }
  82. },
  83. mode: 'production',
  84. output: {
  85. publicPath: 'http://cld2.com:9090/',
  86. filename: 'nodejs/[name].[hash].bundle.js',
  87. },
  88. mode: 'development',
  89. devServer: {
  90. host: '127.0.0.1',
  91. allowedHosts: [
  92. 'cld2.com'
  93. ],
  94. proxy: { //设置代理
  95. "/cld2": {
  96. target: "http://192.168.1.26:7001/",
  97. pathRewrite: { "^/cld2": "/cld2" },
  98. changeOrigin: true
  99. }
  100. },
  101. contentBase: path.resolve(__dirname, '../dist'),
  102. open: true,
  103. port: 9090,
  104. compress: true,
  105. hot: true,
  106. historyApiFallback: {
  107. rewrites: [
  108. {
  109. // from: /\/hr/, to: '/hr',
  110. // from: /\/hr\/indof/, to: '/hr',
  111. from: '/contact', to: '/contact',
  112. //from: /^\/contact\/company/, to: '/contact',
  113. //from: /^\/product/, to: '/product',
  114. //from: /^\/product\/lockCount/, to: '/product',
  115. //from: /product/, to: '/product',
  116. //from: /product\/lockCount/, to: '/product',
  117. // from: /^\/wo\/wo/, to: '/',
  118. // from: /^\/contact/, to: '/contact',
  119. // from: /^\/contact\/company/, to: '/contact',
  120. // from: /^\/product/, to: '/product',
  121. // from: /^\/product\/company/, to: '/product',
  122. // from: /^\/product\/hr/, to: '/hr',
  123. },
  124. {
  125. from: '/product', to: '/product',
  126. },
  127. {
  128. from: '/login', to: '/login',
  129. },
  130. ]
  131. }
  132. },
  133. plugins: [
  134. new HtmlWebpackPlugin({
  135. template: 'public/index.html',
  136. filename: 'index.html',
  137. chunks: ['workbench', 'framework'],
  138. // inject: 'body',
  139. // minify: {
  140. // removeComments: true,
  141. // collapseWhitespace: true,
  142. // },
  143. }),
  144. new MiniCssExtractPlugin({
  145. filename: 'nodecss/[name].[hash].css',
  146. chunkFilename: 'css/[id].[hash].css',
  147. }),
  148. //new CleanWebpackPlugin(),
  149. ]
  150. });