webpack.config.prod.js 977 B

12345678910111213141516171819202122232425262728293031
  1. const merge = require('webpack-merge')
  2. const TerserPlugin = require('terser-webpack-plugin')
  3. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  4. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  5. const base = require('./webpack.config')
  6. module.exports = merge(base, {
  7. mode: 'production',
  8. // Enable a full source map. Generates a comment linking to the source map
  9. devtool: 'source-map',
  10. output: {
  11. // Override filename to include hash for immutable caching
  12. filename: 'js/[name]-[chunkhash].js'
  13. },
  14. optimization: {
  15. // Minify JS (with Terser) and CSS (with cssnano)
  16. minimizer: [new TerserPlugin(), new OptimizeCssAssetsPlugin()]
  17. },
  18. plugins: [
  19. // Extract CSS to a separate file (rather than inlining to a <style> tag)
  20. new MiniCssExtractPlugin({
  21. // Output to public/stylesheets directory and append hash for immutable caching
  22. filename: 'stylesheets/[name]-[chunkhash].css'
  23. })
  24. ]
  25. })