webpack.config.js 1.8KB

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