webpack.config.prod.js 1.6 KB

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