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-dom',
  19. // 'react-select',
  20. 'redux',
  21. 'redux-logger',
  22. // 'redux-saga',
  23. 'redux-thunk',
  24. 'whatwg-fetch',
  25. 'classnames'
  26. ]
  27. },
  28. output: {
  29. path: path.resolve(__dirname, 'dist'),
  30. filename: 'tracim.app.entry.js',
  31. pathinfo: !isProduction
  32. },
  33. devServer: {
  34. contentBase: path.join(__dirname, 'dist/'),
  35. port: 8090,
  36. hot: true,
  37. noInfo: true,
  38. overlay: {
  39. warnings: false,
  40. errors: true
  41. },
  42. historyApiFallback: true
  43. // headers: {
  44. // 'Access-Control-Allow-Origin': '*'
  45. // }
  46. },
  47. devtool: isProduction ? false : 'cheap-module-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:[
  80. ...[ // generic plugins always present
  81. new webpack.optimize.CommonsChunkPlugin({
  82. name: 'vendor',
  83. filename: 'tracim.vendor.bundle.js'
  84. })
  85. ],
  86. ...(isProduction
  87. ? [ // production specific plugins
  88. new webpack.DefinePlugin({
  89. 'process.env': { 'NODE_ENV': JSON.stringify('production') }
  90. }),
  91. new webpack.optimize.UglifyJsPlugin({
  92. compress: { warnings: false }
  93. })
  94. ]
  95. : [] // development specific plugins
  96. )
  97. ]
  98. }