webpack.config.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const isProduction = process.env.NODE_ENV === 'production'
  4. module.exports = {
  5. entry: {
  6. app: ['babel-polyfill', 'whatwg-fetch', './src/index.js'],
  7. vendor: [
  8. 'babel-plugin-transform-class-properties',
  9. 'babel-plugin-transform-object-assign',
  10. 'babel-plugin-transform-object-rest-spread',
  11. 'babel-polyfill',
  12. // 'lodash.pull',
  13. // 'lodash.reject',
  14. // 'lodash.uniqby',
  15. 'react',
  16. 'react-dom',
  17. 'react-redux',
  18. // 'react-router',
  19. 'react-router-dom',
  20. // 'react-select',
  21. 'redux',
  22. 'redux-logger',
  23. // 'redux-saga',
  24. 'redux-thunk',
  25. 'whatwg-fetch',
  26. // 'classnames'
  27. ]
  28. },
  29. output: {
  30. path: path.resolve(__dirname, 'dist'),
  31. filename: 'tracim.app.entry.js',
  32. pathinfo: !isProduction
  33. },
  34. devServer: {
  35. contentBase: path.join(__dirname, 'dist/'),
  36. port: 8090,
  37. hot: true,
  38. noInfo: true,
  39. overlay: {
  40. warnings: false,
  41. errors: true
  42. }
  43. // headers: {
  44. // 'Access-Control-Allow-Origin': '*'
  45. // }
  46. },
  47. devtool: isProduction ? false : 'cheap-eval-source-map',
  48. module: {
  49. rules: [{
  50. test: /\.jsx?$/,
  51. enforce: 'pre',
  52. use: 'standard-loader',
  53. exclude: [/node_modules/]
  54. }, {
  55. test: [/\.js$/, /\.jsx$/],
  56. loader: 'babel-loader',
  57. options: {
  58. presets: ['env', 'react'],
  59. plugins: ['transform-object-rest-spread', 'transform-class-properties', 'transform-object-assign']
  60. },
  61. exclude: [/node_modules/]
  62. }, {
  63. test: /\.css$/,
  64. use: ['style-loader', 'css-loader']
  65. }, {
  66. test: /\.styl$/,
  67. use: ['style-loader', 'css-loader', 'stylus-loader']
  68. }, {
  69. test: /\.(jpg|png|svg)$/,
  70. loader: 'url-loader',
  71. options: {
  72. limit: 25000
  73. }
  74. }]
  75. },
  76. resolve: {
  77. extensions: ['.js', '.jsx']
  78. },
  79. plugins: isProduction
  80. ? [
  81. new webpack.optimize.CommonsChunkPlugin({
  82. name: 'vendor',
  83. filename: 'tracim.vendor.bundle.js'
  84. }),
  85. new webpack.DefinePlugin({
  86. 'process.env': { 'NODE_ENV': JSON.stringify('production') }
  87. }),
  88. new webpack.optimize.UglifyJsPlugin({
  89. compress: { warnings: false }
  90. })
  91. ]
  92. : [
  93. new webpack.optimize.CommonsChunkPlugin({
  94. name: 'vendor',
  95. filename: 'tracim.vendor.bundle.js'
  96. })
  97. ]
  98. }