停车场项目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.

155 lines
4.0 KiB

  1. process.env.NODE_ENV = "production"
  2. const path = require("path")
  3. const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
  4. const { merge } = require("webpack-merge")
  5. const commonConfig = require("./webpack.common")
  6. const MiniCssExtractPlugin = require("mini-css-extract-plugin")
  7. const CopyPlugin = require("copy-webpack-plugin")
  8. const TerserPlugin = require("terser-webpack-plugin")
  9. const SpeedMeasurePlugin = require("speed-measure-webpack-plugin")
  10. const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin
  11. const isSMP = process.env.smp == "true"
  12. const isAnalyze = process.env.analyze == "true"
  13. const miniCssExtractPluginConfig = new MiniCssExtractPlugin({
  14. filename: "static/css/[name]_[chunkhash:4].css"
  15. })
  16. let _prodConfig = {
  17. mode: "production",
  18. stats: "errors-only",
  19. devtool: "source-map",
  20. module: {
  21. rules: [
  22. {
  23. test: /\.css$/,
  24. use: [
  25. MiniCssExtractPlugin.loader,
  26. "style-loader",
  27. "css-loader",
  28. {
  29. loader: "postcss-loader",
  30. options: {
  31. postcssOptions: {
  32. plugins: [["autoprefixer"]],
  33. },
  34. },
  35. },
  36. ],
  37. },
  38. {
  39. test: /\.scss$/,
  40. use: [
  41. MiniCssExtractPlugin.loader,
  42. "css-loader",
  43. {
  44. loader: "postcss-loader",
  45. options: {
  46. postcssOptions: {
  47. plugins: [["autoprefixer"]],
  48. },
  49. },
  50. },
  51. "sass-loader",
  52. ],
  53. },
  54. ],
  55. },
  56. optimization: {
  57. minimize: true,
  58. minimizer: [
  59. new CssMinimizerPlugin({
  60. include: "src",
  61. }),
  62. new TerserPlugin({
  63. extractComments: false,
  64. include: "src",
  65. }),
  66. ],
  67. splitChunks: {
  68. chunks: "all",
  69. minSize: 20000,
  70. minChunks: 1,
  71. maxAsyncRequests: 6,
  72. maxInitialRequests: 8,
  73. automaticNameDelimiter: "~",
  74. // name: true,
  75. cacheGroups: {
  76. locallibs: {
  77. test: /[\\/]node_modules[\\/](react|react-dom|redux|react-redux|react-router-dom|antd)[\\/]/,
  78. name: "locallibs",
  79. priority: -4,
  80. },
  81. localuis: {
  82. test: /[\\/]node_modules[\\/](@ant-design|moment)[\\/]/,
  83. name: "localuis",
  84. priority: -5,
  85. },
  86. localmobileuis: {
  87. test: /[\\/]node_modules[\\/](antd-mobile)[\\/]/,
  88. name: "localmobileuis",
  89. priority: -6,
  90. },
  91. localcharts: {
  92. test: /[\\/]node_modules[\\/](echarts|echarts-gl|echarts-for-react)[\\/]/,
  93. name: "localcharts",
  94. priority: -7,
  95. },
  96. localvideos: {
  97. test: /[\\/]node_modules[\\/](xgplayer|xgplayer-flv|flv.js)[\\/]/,
  98. name: "localvideos",
  99. priority: -8,
  100. },
  101. localmaps: {
  102. test: /[\\/]node_modules[\\/](leaflet|leaflet.chinatmsproviders)[\\/]/,
  103. name: "localmaps",
  104. priority: -9,
  105. },
  106. vendors: {
  107. test: /[\\/]node_modules[\\/]/,
  108. name: "vendors",
  109. priority: -10,
  110. },
  111. default: {
  112. name: "default",
  113. minChunks: 2,
  114. priority: -20,
  115. reuseExistingChunk: true,
  116. },
  117. },
  118. },
  119. },
  120. plugins: [
  121. miniCssExtractPluginConfig,
  122. new CopyPlugin({
  123. patterns: [
  124. {
  125. from: "public/static/",
  126. to: "static/",
  127. },
  128. {
  129. from: "release",
  130. to: "static/",
  131. },
  132. ],
  133. }),
  134. isAnalyze && new BundleAnalyzerPlugin(),
  135. ].filter(Boolean),
  136. }
  137. let prodConfig = merge(commonConfig, _prodConfig)
  138. if (!isSMP) {
  139. module.exports = prodConfig
  140. } else {
  141. // 处理SpeedMeasurePlugin兼容问题
  142. let index = prodConfig.plugins.findIndex(plugin => {
  143. return plugin === miniCssExtractPluginConfig
  144. })
  145. prodConfig.plugins.splice(index, 1)
  146. const smp = new SpeedMeasurePlugin()
  147. prodConfig = smp.wrap(prodConfig)
  148. prodConfig.plugins.push(miniCssExtractPluginConfig)
  149. module.exports = prodConfig
  150. }