webpack.pro.config.js 2.2 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. './src/index.tsx'
  9. ],
  10. output: {
  11. path: resolve(__dirname, 'build'),//打包后的文件存放的地方
  12. filename: "react-dragger-layout.js",//打包后输出文件的文件名
  13. publicPath: "/"
  14. },
  15. devServer: {
  16. contentBase: resolve(__dirname, 'build'),
  17. hot: true,
  18. publicPath: '/',
  19. },
  20. resolve: {
  21. // Add '.ts' and '.tsx' as resolvable extensions.
  22. extensions: [".ts", ".tsx", ".js", ".json"]
  23. },
  24. module: {
  25. rules: [
  26. {
  27. test: /\.jsx?$/,
  28. use: [
  29. 'babel-loader',
  30. ],
  31. exclude: /node_modules/
  32. },
  33. {
  34. test: /\.css$/,
  35. use: [
  36. 'style-loader', 'css-loader'
  37. ],
  38. exclude: /node_modules/
  39. },
  40. // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
  41. { test: /\.tsx?$/, loader: "awesome-typescript-loader" },
  42. // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
  43. { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
  44. ],
  45. },
  46. plugins: [
  47. // new webpack.HotModuleReplacementPlugin(),
  48. // new webpack.NamedModulesPlugin(),
  49. new webpack.optimize.UglifyJsPlugin({
  50. compress: {
  51. warnings: false,
  52. comparisons: false,
  53. },
  54. output: {
  55. comments: false,
  56. // Turned on because emoji and regex is not minified properly using default
  57. // https://github.com/facebookincubator/create-react-app/issues/2488
  58. ascii_only: true,
  59. },
  60. }),
  61. new webpack.DefinePlugin({
  62. 'process.env': {
  63. NODE_ENV: JSON.stringify(process.env.NODE_ENV),
  64. },
  65. }),
  66. ],
  67. // devtool: "cheap-eval-source-map",
  68. };