webpack.prod.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @author: Yuki Takei <yuki@weseek.co.jp>
  3. */
  4. const helpers = require('./helpers');
  5. /**
  6. * Webpack Plugins
  7. */
  8. const UglifyJsPlugin = require('uglifyjs-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: /\.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. include: [helpers.root('resource/styles/scss')]
  39. }
  40. ]
  41. },
  42. plugins: [
  43. new MiniCssExtractPlugin({
  44. filename: '[name].[hash].css',
  45. }),
  46. new BundleAnalyzerPlugin({
  47. analyzerMode: ANALYZE ? 'static' : 'disabled',
  48. reportFilename: helpers.root('report/bundle-analyzer.html'),
  49. openAnalyzer: false,
  50. }),
  51. ],
  52. optimization: {
  53. minimizer: [
  54. new UglifyJsPlugin({
  55. cache: true,
  56. parallel: true,
  57. }),
  58. new OptimizeCSSAssetsPlugin({})
  59. ],
  60. },
  61. });