webpack.prod.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 ExtractTextPlugin = require('extract-text-webpack-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: ExtractTextPlugin.extract({
  28. use: [
  29. 'css-loader',
  30. { loader: 'postcss-loader', options: {
  31. sourceMap: false,
  32. plugins: (loader) => [
  33. require('autoprefixer')()
  34. ]
  35. } },
  36. 'sass-loader'
  37. ]
  38. }),
  39. include: [helpers.root('resource/styles/scss')]
  40. }
  41. ]
  42. },
  43. plugins: [
  44. new ExtractTextPlugin({
  45. filename: '[name].[hash].css',
  46. }),
  47. new BundleAnalyzerPlugin({
  48. analyzerMode: ANALYZE ? 'static' : 'disabled',
  49. reportFilename: helpers.root('report/bundle-analyzer.html'),
  50. openAnalyzer: false,
  51. }),
  52. ],
  53. optimization: {
  54. minimizer: [
  55. new UglifyJsPlugin({
  56. cache: true,
  57. parallel: true,
  58. }),
  59. new OptimizeCSSAssetsPlugin({})
  60. ],
  61. },
  62. });