webpack.config.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/asset'),
  31. filename: 'tracim.app.entry.js',
  32. pathinfo: !isProduction,
  33. publicPath: '/asset/'
  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: 'file-loader',
  73. options: {
  74. name: '[name].[ext]',
  75. outputPath: 'images/', // asset/ is in output.path
  76. limit: 2000
  77. }
  78. }]
  79. },
  80. resolve: {
  81. extensions: ['.js', '.jsx']
  82. },
  83. plugins:[
  84. ...[ // generic plugins always present
  85. new webpack.optimize.CommonsChunkPlugin({
  86. name: 'vendor',
  87. filename: 'tracim.vendor.bundle.js'
  88. })
  89. // new dashboardPlugin()
  90. ],
  91. ...(isProduction
  92. ? [ // production specific plugins
  93. new webpack.DefinePlugin({
  94. 'process.env': { 'NODE_ENV': JSON.stringify('production') }
  95. }),
  96. new webpack.optimize.UglifyJsPlugin({
  97. compress: { warnings: false }
  98. })
  99. ]
  100. : [] // development specific plugins
  101. )
  102. ]
  103. }