webpack.config.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. loader: 'style-loader!css-loader'//在webpack-dev中不能使用--hot
  36. },
  37. // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
  38. { test: /\.tsx?$/, loader: "awesome-typescript-loader" },
  39. // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
  40. { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
  41. ]
  42. },
  43. plugins: [
  44. new webpack.HotModuleReplacementPlugin(),
  45. new webpack.NamedModulesPlugin(),
  46. new webpack.optimize.UglifyJsPlugin({
  47. compress: {
  48. warnings: false
  49. },
  50. }),
  51. new webpack.DefinePlugin({
  52. 'process.env': {
  53. NODE_ENV: JSON.stringify(process.env.NODE_ENV),
  54. },
  55. }),
  56. ],
  57. devtool: "cheap-eval-source-map",
  58. };