webpack.prod.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const merge = require('webpack-merge')
  2. const commonConf = require('./webpack.common.js')
  3. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  4. const TerserJSPlugin = require('terser-webpack-plugin')
  5. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  6. const CleanWebpackPlugin = require('clean-webpack-plugin')
  7. const path = require('path')
  8. const prodConf = {
  9. mode: 'production',
  10. devtool: 'cheap-module-source-map',
  11. output: {
  12. path: path.resolve(__dirname, '../../../pub/zq2019/ydzy_simulator'),
  13. publicPath: '//pub.dwstatic.com/zq2019/ydzy_simulator/',
  14. filename: 'js/[name]_[contenthash:5].js',
  15. },
  16. module: {
  17. rules: [
  18. {
  19. test: /(?<!\.module)\.(scss|css)$/,
  20. use: [
  21. MiniCssExtractPlugin.loader,
  22. {
  23. loader: 'css-loader',
  24. options: {
  25. importLoaders: 2
  26. }
  27. },
  28. 'sass-loader',
  29. 'postcss-loader'
  30. ]
  31. },
  32. {
  33. test: /(?<=\.module)\.(scss|css)$/,
  34. use: [
  35. MiniCssExtractPlugin.loader,
  36. {
  37. loader: 'css-loader',
  38. options: {
  39. importLoaders: 2,
  40. modules: true
  41. }
  42. },
  43. 'sass-loader',
  44. 'postcss-loader'
  45. ]
  46. }
  47. ]
  48. },
  49. plugins: [
  50. new MiniCssExtractPlugin({
  51. filename: 'css/[name]_[contenthash:5].css',
  52. chunkFilename: 'css/[id]_[contenthash:5].css'
  53. }),
  54. new CleanWebpackPlugin()
  55. ],
  56. optimization: {
  57. minimizer: [
  58. new TerserJSPlugin({
  59. sourceMap: true
  60. }),
  61. new OptimizeCSSAssetsPlugin({})
  62. ]
  63. }
  64. }
  65. module.exports = merge(commonConf, prodConf)