webpack.config.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const isProduction = process.env.NODE_ENV === 'production'
  4. const dashboardPlugin = require('webpack-dashboard/plugin')
  5. module.exports = {
  6. entry: {
  7. app: ['babel-polyfill', 'whatwg-fetch', './src/index.js'],
  8. vendor: [
  9. 'babel-plugin-transform-class-properties',
  10. 'babel-plugin-transform-object-assign',
  11. 'babel-plugin-transform-object-rest-spread',
  12. 'babel-polyfill',
  13. // 'lodash.pull',
  14. // 'lodash.reject',
  15. // 'lodash.uniqby',
  16. 'react',
  17. 'react-dom',
  18. 'react-redux',
  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. historyApiFallback: true
  44. // headers: {
  45. // 'Access-Control-Allow-Origin': '*'
  46. // }
  47. },
  48. devtool: isProduction ? false : 'cheap-module-source-map',
  49. module: {
  50. rules: [{
  51. test: /\.jsx?$/,
  52. enforce: 'pre',
  53. use: 'standard-loader',
  54. exclude: [/node_modules/]
  55. }, {
  56. test: [/\.js$/, /\.jsx$/],
  57. loader: 'babel-loader',
  58. options: {
  59. presets: ['env', 'react'],
  60. plugins: ['transform-object-rest-spread', 'transform-class-properties', 'transform-object-assign']
  61. },
  62. exclude: [/node_modules/]
  63. }, {
  64. test: /\.css$/,
  65. use: ['style-loader', 'css-loader']
  66. }, {
  67. test: /\.styl$/,
  68. use: ['style-loader', 'css-loader', 'stylus-loader']
  69. }, {
  70. test: /\.(jpg|png|svg)$/,
  71. loader: 'url-loader',
  72. options: {
  73. limit: 2000
  74. }
  75. }]
  76. },
  77. resolve: {
  78. extensions: ['.js', '.jsx']
  79. },
  80. plugins:[
  81. ...[ // generic plugins always present
  82. new webpack.optimize.CommonsChunkPlugin({
  83. name: 'vendor',
  84. filename: 'tracim.vendor.bundle.js'
  85. })
  86. // new dashboardPlugin()
  87. ],
  88. ...(isProduction
  89. ? [ // production specific plugins
  90. new webpack.DefinePlugin({
  91. 'process.env': { 'NODE_ENV': JSON.stringify('production') }
  92. }),
  93. new webpack.optimize.UglifyJsPlugin({
  94. compress: { warnings: false }
  95. })
  96. ]
  97. : [] // development specific plugins
  98. )
  99. ]
  100. }