webpack.config.js 2.1KB

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