webpack.prod.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @author: Yuki Takei <yuki@weseek.co.jp>
  3. */
  4. /**
  5. * Webpack Plugins
  6. */
  7. const TerserPlugin = require('terser-webpack-plugin');
  8. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  9. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  10. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  11. const helpers = require('../src/lib/util/helpers');
  12. /**
  13. * Webpack Constants
  14. */
  15. const { ANALYZE } = process.env;
  16. module.exports = require('./webpack.common')({
  17. mode: 'production',
  18. devtool: undefined,
  19. output: {
  20. filename: '[name].[chunkhash].bundle.js',
  21. chunkFilename: '[name].[chunkhash].chunk.js',
  22. },
  23. module: {
  24. rules: [
  25. {
  26. test: /\.(css|scss)$/,
  27. use: [
  28. MiniCssExtractPlugin.loader,
  29. 'css-loader',
  30. {
  31. loader: 'postcss-loader',
  32. options: {
  33. sourceMap: false,
  34. plugins: (loader) => {
  35. return [
  36. require('autoprefixer')(),
  37. ];
  38. },
  39. },
  40. },
  41. 'sass-loader',
  42. ],
  43. exclude: [helpers.root('src/client/js/legacy')],
  44. },
  45. {
  46. test: /\.(css|scss)$/,
  47. use: ['style-loader', 'css-loader', 'sass-loader'],
  48. include: [helpers.root('src/client/js/legacy')],
  49. },
  50. ],
  51. },
  52. plugins: [
  53. new MiniCssExtractPlugin({
  54. filename: '[name].[hash].css',
  55. }),
  56. new BundleAnalyzerPlugin({
  57. analyzerMode: ANALYZE ? 'static' : 'disabled',
  58. reportFilename: helpers.root('report/bundle-analyzer.html'),
  59. openAnalyzer: false,
  60. }),
  61. ],
  62. optimization: {
  63. minimizer: [
  64. new TerserPlugin({}),
  65. new OptimizeCSSAssetsPlugin({}),
  66. ],
  67. },
  68. });