webpack.prod.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @author: Yuki Takei <yuki@weseek.co.jp>
  3. */
  4. const helpers = require('./helpers');
  5. const webpack = require('webpack');
  6. const webpackMerge = require('webpack-merge'); // used to merge webpack configs
  7. const commonConfig = require('./webpack.common.js'); // the settings that are common to prod and dev
  8. /**
  9. * Webpack Plugins
  10. */
  11. const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
  12. const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
  13. const OptimizeJsPlugin = require('optimize-js-plugin');
  14. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  15. /**
  16. * Webpack Constants
  17. */
  18. const ANALYZE = process.env.ANALYZE;
  19. const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
  20. const HOST = process.env.HOST || 'localhost';
  21. const PORT = process.env.PORT || 3000;
  22. module.exports = function (env) {
  23. return webpackMerge(commonConfig({ env: ENV }), {
  24. devtool: 'source-map',
  25. output: {
  26. path: helpers.root('public/js'),
  27. publicPath: '/js/',
  28. filename: '[name].[chunkhash].bundle.js',
  29. sourceMapFilename: '[name].[chunkhash].bundle.map',
  30. chunkFilename: '[id].[chunkhash].chunk.js'
  31. },
  32. module: {
  33. rules: [
  34. ]
  35. },
  36. plugins: [
  37. new webpack.DefinePlugin({
  38. 'process.env': {
  39. NODE_ENV: JSON.stringify(ENV),
  40. }
  41. }),
  42. new OptimizeJsPlugin({
  43. sourceMap: false
  44. }),
  45. new UglifyJsPlugin({
  46. // beautify: true, //debug
  47. // mangle: false, //debug
  48. // dead_code: false, //debug
  49. // unused: false, //debug
  50. // deadCode: false, //debug
  51. // compress: {
  52. // screw_ie8: true,
  53. // keep_fnames: true,
  54. // drop_debugger: false,
  55. // dead_code: false,
  56. // unused: false
  57. // }, // debug
  58. // comments: true, //debug
  59. beautify: false, //prod
  60. output: {
  61. comments: false
  62. }, //prod
  63. mangle: {
  64. screw_ie8: true
  65. }, //prod
  66. compress: {
  67. screw_ie8: true,
  68. warnings: false,
  69. conditionals: true,
  70. unused: true,
  71. comparisons: true,
  72. sequences: true,
  73. dead_code: true,
  74. evaluate: true,
  75. if_return: true,
  76. join_vars: true,
  77. negate_iife: false // we need this for lazy v8
  78. },
  79. }),
  80. new BundleAnalyzerPlugin({
  81. analyzerMode: ANALYZE ? 'static' : 'disabled',
  82. reportFilename: helpers.root('report/bundle-analyzer.html'),
  83. openAnalyzer: false,
  84. }),
  85. ],
  86. });
  87. }