webpack.config.js 2.3KB

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