webpack.config.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { resolve } = require('path');
  2. const webpack = require('webpack');
  3. module.exports = {
  4. context: __dirname,
  5. entry: [
  6. 'react-hot-loader/patch',
  7. 'webpack/hot/only-dev-server',
  8. './app/src/index.js'
  9. ],
  10. output: {
  11. path: resolve(__dirname, 'build'),//打包后的文件存放的地方
  12. filename: "bundle.js",//打包后输出文件的文件名
  13. publicPath: "/",
  14. libraryTarget: 'commonjs2'
  15. },
  16. devServer: {
  17. contentBase: resolve(__dirname, 'build'),
  18. hot: true,
  19. publicPath: '/',
  20. },
  21. module: {
  22. rules: [
  23. {
  24. test: /\.jsx?$/,
  25. use: [
  26. 'babel-loader',
  27. ],
  28. exclude: /node_modules/
  29. },
  30. {
  31. test: /\.css$/,
  32. loader: 'style-loader!css-loader'//在webpack-dev中不能使用--hot
  33. },
  34. ]
  35. },
  36. externals: {
  37. 'react': 'commonjs react' // this line is just to use the React dependency of our parent-testing-project instead of using our own React.
  38. },
  39. plugins: [
  40. new webpack.HotModuleReplacementPlugin(),
  41. new webpack.NamedModulesPlugin(),
  42. new webpack.optimize.UglifyJsPlugin({
  43. compress: {
  44. warnings: false
  45. }
  46. }),
  47. new webpack.DefinePlugin({
  48. 'process.env': {
  49. NODE_ENV: JSON.stringify(process.env.NODE_ENV),
  50. },
  51. }),
  52. ],
  53. devtool: "cheap-eval-source-map",
  54. };