webpack.config.prod.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { merge } = require('webpack-merge')
  2. const TerserPlugin = require('terser-webpack-plugin')
  3. const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
  4. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  5. const base = require('./webpack.config')
  6. module.exports = merge(
  7. base,
  8. {
  9. mode: 'production',
  10. // Enable a full source map. Generates a comment linking to the source map
  11. devtool: 'hidden-source-map',
  12. optimization: {
  13. // Minify JS (with Terser) and CSS (with cssnano)
  14. minimizer: [
  15. new TerserPlugin({
  16. terserOptions: {
  17. keep_classnames: /(Error|Exception)$/,
  18. keep_fnames: /(Error|Exception)$/,
  19. },
  20. }),
  21. new CssMinimizerPlugin(),
  22. ],
  23. },
  24. plugins: [
  25. // Extract CSS to a separate file (rather than inlining to a <style> tag)
  26. new MiniCssExtractPlugin({
  27. // Output to public/stylesheets directory and append hash for immutable
  28. // caching
  29. filename: 'stylesheets/[name]-[contenthash].css',
  30. }),
  31. ],
  32. },
  33. {}
  34. )