webpack.config.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. publicPath: '/'
  34. },
  35. devServer: {
  36. contentBase: path.join(__dirname, 'dist/'),
  37. port: 8090,
  38. hot: true,
  39. noInfo: true,
  40. overlay: {
  41. warnings: false,
  42. errors: true
  43. },
  44. historyApiFallback: true
  45. // headers: {
  46. // 'Access-Control-Allow-Origin': '*'
  47. // }
  48. },
  49. devtool: isProduction ? false : 'cheap-module-source-map',
  50. module: {
  51. rules: [{
  52. test: /\.jsx?$/,
  53. enforce: 'pre',
  54. use: 'standard-loader',
  55. exclude: [/node_modules/]
  56. }, {
  57. test: [/\.js$/, /\.jsx$/],
  58. loader: 'babel-loader',
  59. options: {
  60. presets: ['env', 'react'],
  61. plugins: ['transform-object-rest-spread', 'transform-class-properties', 'transform-object-assign']
  62. },
  63. exclude: [/node_modules/]
  64. }, {
  65. test: /\.css$/,
  66. use: ['style-loader', 'css-loader']
  67. }, {
  68. test: /\.styl$/,
  69. use: ['style-loader', 'css-loader', 'stylus-loader']
  70. }, {
  71. test: /\.(jpg|png|svg)$/,
  72. loader: 'url-loader',
  73. options: {
  74. limit: 2000
  75. }
  76. }]
  77. },
  78. resolve: {
  79. extensions: ['.js', '.jsx']
  80. },
  81. plugins:[
  82. ...[ // generic plugins always present
  83. new webpack.optimize.CommonsChunkPlugin({
  84. name: 'vendor',
  85. filename: 'tracim.vendor.bundle.js'
  86. })
  87. // new dashboardPlugin()
  88. ],
  89. ...(isProduction
  90. ? [ // production specific plugins
  91. new webpack.DefinePlugin({
  92. 'process.env': { 'NODE_ENV': JSON.stringify('production') }
  93. }),
  94. new webpack.optimize.UglifyJsPlugin({
  95. compress: { warnings: false }
  96. })
  97. ]
  98. : [] // development specific plugins
  99. )
  100. ]
  101. }