webpack.config.prod.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict'
  2. const webpack = require('webpack')
  3. const { merge } = require('webpack-merge')
  4. const baseConfig = require('./webpack.config.base')
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  6. const TerserPlugin = require("terser-webpack-plugin");
  7. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  8. const CompressionPlugin = require("compression-webpack-plugin");
  9. module.exports = merge(baseConfig, {
  10. mode: 'production',
  11. module: {
  12. rules: [
  13. {
  14. test: /\.css?$/,
  15. use: [
  16. {
  17. loader: MiniCssExtractPlugin.loader,
  18. options: {
  19. publicPath: '',
  20. },
  21. },
  22. 'css-loader'
  23. ]
  24. }, {
  25. test: /\.scss?$/,
  26. use: [
  27. {
  28. loader: MiniCssExtractPlugin.loader,
  29. options: {
  30. publicPath: '',
  31. },
  32. },
  33. 'css-loader',
  34. 'sass-loader'
  35. ]
  36. }, {
  37. test: /\.(png|jpg|gif|svg)$/,
  38. use: [
  39. {
  40. loader: 'url-loader',
  41. options: {
  42. limit: 5000
  43. }
  44. }
  45. ]
  46. }
  47. ]
  48. },
  49. optimization: {
  50. minimize: true,
  51. minimizer: [
  52. new TerserPlugin({
  53. parallel: true,
  54. test: /\.(js|vue)$/,
  55. // extractComments: true
  56. terserOptions: {
  57. compress: {
  58. // drop_console: true,
  59. pure_funcs: [
  60. 'console.log',
  61. 'console.info',
  62. 'console.debug'
  63. // 'console.warn'
  64. ]
  65. },
  66. },
  67. })
  68. ],
  69. },
  70. plugins: [
  71. new webpack.DefinePlugin({
  72. 'process.env.NODE_ENV': JSON.stringify('production')
  73. }),
  74. new BundleAnalyzerPlugin({
  75. 'analyzerMode': 'static'
  76. }),
  77. new CompressionPlugin(),
  78. ]
  79. })