webpack.config.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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: {
  16. commonjs: 'react',
  17. commonjs2: 'react',
  18. amd: 'react',
  19. root: '_'
  20. }
  21. },
  22. devServer: {
  23. contentBase: path.join(__dirname, 'dist/'),
  24. port: 8071,
  25. hot: true,
  26. noInfo: true,
  27. overlay: {
  28. warnings: false,
  29. errors: true
  30. },
  31. historyApiFallback: true
  32. // headers: {
  33. // 'Access-Control-Allow-Origin': '*'
  34. // }
  35. },
  36. devtool: isProduction ? false : 'cheap-module-source-map',
  37. module: {
  38. rules: [{
  39. test: /\.jsx?$/,
  40. enforce: 'pre',
  41. use: 'standard-loader',
  42. exclude: [/node_modules/]
  43. }, {
  44. test: [/\.js$/, /\.jsx$/],
  45. loader: 'babel-loader',
  46. options: {
  47. presets: ['env', 'react'],
  48. plugins: ['transform-object-rest-spread', 'transform-class-properties', 'transform-object-assign']
  49. },
  50. exclude: [/node_modules/]
  51. }, {
  52. test: /\.css$/,
  53. use: ['style-loader', 'css-loader']
  54. }, {
  55. test: /\.styl$/,
  56. use: ['style-loader', 'css-loader', 'stylus-loader']
  57. }, {
  58. test: /\.(jpg|png|svg)$/,
  59. loader: 'url-loader',
  60. options: {
  61. limit: 25000
  62. }
  63. }]
  64. },
  65. resolve: {
  66. extensions: ['.js', '.jsx']
  67. },
  68. plugins:[
  69. ...[], // generic plugins always present
  70. ...(isProduction
  71. ? [ // production specific plugins
  72. new webpack.DefinePlugin({
  73. 'process.env': { 'NODE_ENV': JSON.stringify('production') }
  74. }),
  75. new webpack.optimize.UglifyJsPlugin({
  76. compress: { warnings: false }
  77. })
  78. ]
  79. : [] // development specific plugins
  80. )
  81. ]
  82. }