2
0

webpack.prod.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 ExtractTextPlugin = require('extract-text-webpack-plugin');
  13. const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
  14. const OptimizeJsPlugin = require('optimize-js-plugin');
  15. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  16. /**
  17. * Webpack Constants
  18. */
  19. const ANALYZE = process.env.ANALYZE;
  20. const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
  21. const HOST = process.env.HOST || 'localhost';
  22. const PORT = process.env.PORT || 3000;
  23. module.exports = function (env) {
  24. return webpackMerge(commonConfig({ env: ENV }), {
  25. devtool: undefined,
  26. output: {
  27. path: helpers.root('public/js'),
  28. publicPath: '/js/',
  29. filename: '[name].[chunkhash].bundle.js',
  30. sourceMapFilename: '[name].[chunkhash].bundle.map',
  31. chunkFilename: '[id].[chunkhash].chunk.js'
  32. },
  33. module: {
  34. rules: [
  35. ]
  36. },
  37. plugins: [
  38. new webpack.DefinePlugin({
  39. 'process.env': {
  40. NODE_ENV: JSON.stringify(ENV),
  41. }
  42. }),
  43. new ExtractTextPlugin('[name].[contenthash].css'),
  44. new OptimizeJsPlugin({
  45. sourceMap: false
  46. }),
  47. new UglifyJsPlugin({
  48. // beautify: true, //debug
  49. // mangle: false, //debug
  50. // dead_code: false, //debug
  51. // unused: false, //debug
  52. // deadCode: false, //debug
  53. // compress: {
  54. // screw_ie8: true,
  55. // keep_fnames: true,
  56. // drop_debugger: false,
  57. // dead_code: false,
  58. // unused: false
  59. // }, // debug
  60. // comments: true, //debug
  61. beautify: false, //prod
  62. output: {
  63. comments: false
  64. }, //prod
  65. mangle: {
  66. screw_ie8: true
  67. }, //prod
  68. compress: {
  69. screw_ie8: true,
  70. warnings: false,
  71. conditionals: true,
  72. unused: true,
  73. comparisons: true,
  74. sequences: true,
  75. dead_code: true,
  76. evaluate: true,
  77. if_return: true,
  78. join_vars: true,
  79. negate_iife: false // we need this for lazy v8
  80. },
  81. }),
  82. new BundleAnalyzerPlugin({
  83. analyzerMode: ANALYZE ? 'static' : 'disabled',
  84. reportFilename: helpers.root('report/bundle-analyzer.html'),
  85. openAnalyzer: false,
  86. }),
  87. ],
  88. });
  89. }