webpack.config.prod.js 1.7 KB

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