webpack.config.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. },
  15. devServer: {
  16. contentBase: resolve(__dirname, 'build'),
  17. hot: true,
  18. publicPath: '/',
  19. },
  20. resolve: {
  21. alias: {
  22. 'react': 'luy',
  23. 'react-dom': 'luy'
  24. }
  25. },
  26. module: {
  27. rules: [
  28. {
  29. test: /\.jsx?$/,
  30. use: [
  31. 'babel-loader',
  32. ],
  33. exclude: /node_modules/
  34. },
  35. {
  36. test: /\.css$/,
  37. loader: 'style-loader!css-loader'//在webpack-dev中不能使用--hot
  38. },
  39. ]
  40. },
  41. plugins: [
  42. new webpack.HotModuleReplacementPlugin(),
  43. new webpack.NamedModulesPlugin(),
  44. new webpack.optimize.UglifyJsPlugin({
  45. compress: {
  46. warnings: false
  47. }
  48. }),
  49. new webpack.DefinePlugin({
  50. 'process.env': {
  51. NODE_ENV: JSON.stringify(process.env.NODE_ENV),
  52. },
  53. }),
  54. ],
  55. devtool: "cheap-eval-source-map",
  56. };