webpack.config.js 1.8KB

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