webpack.prod.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @author: Yuki Takei <yuki@weseek.co.jp>
  3. */
  4. const helpers = require('../src/lib/util/helpers');
  5. /**
  6. * Webpack Plugins
  7. */
  8. const TerserPlugin = require('terser-webpack-plugin');
  9. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  10. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  11. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  12. /**
  13. * Webpack Constants
  14. */
  15. const ANALYZE = process.env.ANALYZE;
  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. { loader: 'postcss-loader', options: {
  31. sourceMap: false,
  32. plugins: (loader) => [
  33. require('autoprefixer')()
  34. ]
  35. } },
  36. 'sass-loader'
  37. ],
  38. exclude: [helpers.root('src/client/js/legacy')]
  39. },
  40. {
  41. test: /\.(css|scss)$/,
  42. use: ['style-loader', 'css-loader', 'sass-loader'],
  43. include: [helpers.root('src/client/js/legacy')]
  44. },
  45. ]
  46. },
  47. plugins: [
  48. new MiniCssExtractPlugin({
  49. filename: '[name].[hash].css',
  50. }),
  51. new BundleAnalyzerPlugin({
  52. analyzerMode: ANALYZE ? 'static' : 'disabled',
  53. reportFilename: helpers.root('report/bundle-analyzer.html'),
  54. openAnalyzer: false,
  55. }),
  56. ],
  57. optimization: {
  58. minimizer: [
  59. new TerserPlugin({}),
  60. new OptimizeCSSAssetsPlugin({})
  61. ],
  62. },
  63. });