webpack.config.prod.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. minimizerOptions: {
  23. // disable mergeLonghand to avoid a cssnano bug https://github.com/cssnano/cssnano/issues/864
  24. preset: ['default', { mergeLonghand: false }],
  25. },
  26. }),
  27. ],
  28. },
  29. plugins: [
  30. // Extract CSS to a separate file (rather than inlining to a <style> tag)
  31. new MiniCssExtractPlugin({
  32. // Output to public/stylesheets directory and append hash for immutable
  33. // caching
  34. filename: 'stylesheets/[name]-[contenthash].css',
  35. }),
  36. ],
  37. },
  38. {}
  39. )