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

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