webpack.pro.config.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/App.js'
  9. ],
  10. output: {
  11. path: resolve(__dirname, 'build'),//打包后的文件存放的地方
  12. filename: "react-dragger-layout.js",//打包后输出文件的文件名
  13. publicPath: "/",
  14. libraryTarget: 'umd'
  15. },
  16. devServer: {
  17. contentBase: resolve(__dirname, 'build'),
  18. hot: true,
  19. publicPath: '/',
  20. },
  21. externals: {
  22. 'react': {
  23. 'commonjs': 'react',
  24. 'commonjs2': 'react',
  25. 'amd': 'react',
  26. // React dep should be available as window.React, not window.react
  27. 'root': 'React'
  28. },
  29. 'react-dom': {
  30. 'commonjs': 'react-dom',
  31. 'commonjs2': 'react-dom',
  32. 'amd': 'react-dom',
  33. 'root': 'ReactDOM'
  34. }
  35. },
  36. module: {
  37. rules: [
  38. {
  39. test: /\.jsx?$/,
  40. use: [
  41. 'babel-loader',
  42. ],
  43. exclude: /node_modules/
  44. },
  45. {
  46. test: /\.css$/,
  47. use: [
  48. 'style-loader', 'css-loader'
  49. ],
  50. exclude: /node_modules/
  51. },
  52. ],
  53. },
  54. plugins: [
  55. // new webpack.HotModuleReplacementPlugin(),
  56. // new webpack.NamedModulesPlugin(),
  57. new webpack.optimize.UglifyJsPlugin({
  58. compress: {
  59. warnings: false
  60. }
  61. }),
  62. new webpack.DefinePlugin({
  63. 'process.env': {
  64. NODE_ENV: JSON.stringify(process.env.NODE_ENV),
  65. },
  66. }),
  67. ],
  68. // devtool: "cheap-eval-source-map",
  69. };