webpack.config.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const isProduction = process.env.NODE_ENV === 'production'
  4. console.log('isProduction : ', isProduction)
  5. module.exports = {
  6. entry: isProduction
  7. ? './src/index.js' // only one instance of babel-polyfill is allowed
  8. : ['babel-polyfill', './src/index.dev.js'],
  9. output: {
  10. path: path.resolve(__dirname, 'dist'),
  11. filename: isProduction ? 'workspace.app.js' : 'workspace.app.dev.js',
  12. pathinfo: !isProduction,
  13. library: isProduction ? 'appWorkspace' : undefined,
  14. libraryTarget: isProduction ? 'var' : undefined
  15. },
  16. externals: {},
  17. // isProduction ? { // Côme - since plugins are imported through <script>, cannot externalize libraries
  18. // react: {commonjs: 'react', commonjs2: 'react', amd: 'react', root: '_'},
  19. // 'react-dom': {commonjs: 'react-dom', commonjs2: 'react-dom', amd: 'react-dom', root: '_'},
  20. // classnames: {commonjs: 'classnames', commonjs2: 'classnames', amd: 'classnames', root: '_'},
  21. // 'prop-types': {commonjs: 'prop-types', commonjs2: 'prop-types', amd: 'prop-types', root: '_'},
  22. // tracim_lib: {commonjs: 'tracim_lib', commonjs2: 'tracim_lib', amd: 'tracim_lib', root: '_'}
  23. // }
  24. // : {},
  25. devServer: {
  26. contentBase: path.join(__dirname, 'dist/'),
  27. port: 8074,
  28. hot: true,
  29. noInfo: true,
  30. overlay: {
  31. warnings: false,
  32. errors: true
  33. },
  34. historyApiFallback: true
  35. // headers: {
  36. // 'Access-Control-Allow-Origin': '*'
  37. // }
  38. },
  39. devtool: isProduction ? false : 'cheap-module-source-map',
  40. module: {
  41. rules: [{
  42. test: /\.jsx?$/,
  43. enforce: 'pre',
  44. use: 'standard-loader',
  45. exclude: [/node_modules/]
  46. }, {
  47. test: [/\.js$/, /\.jsx$/],
  48. loader: 'babel-loader',
  49. options: {
  50. presets: ['env', 'react'],
  51. plugins: ['transform-object-rest-spread', 'transform-class-properties', 'transform-object-assign']
  52. },
  53. exclude: [/node_modules/]
  54. }, {
  55. test: /\.css$/,
  56. use: ['style-loader', 'css-loader']
  57. }, {
  58. test: /\.styl$/,
  59. use: ['style-loader', 'css-loader', 'stylus-loader']
  60. }, {
  61. test: /\.(jpg|png|svg)$/,
  62. loader: 'url-loader',
  63. options: {
  64. limit: 25000
  65. }
  66. }]
  67. },
  68. resolve: {
  69. extensions: ['.js', '.jsx']
  70. },
  71. plugins: [
  72. ...[], // generic plugins always present
  73. ...(isProduction
  74. ? [ // production specific plugins
  75. new webpack.DefinePlugin({
  76. 'process.env': { 'NODE_ENV': JSON.stringify('production') }
  77. }),
  78. new webpack.optimize.UglifyJsPlugin({
  79. compress: { warnings: false }
  80. })
  81. ]
  82. : [] // development specific plugins
  83. )
  84. ]
  85. }