webpack.config.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const HtmlWebpackPlugin = require('html-webpack-plugin');
  2. const path = require('path');
  3. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  4. module.exports = {
  5. entry: './src/index.js',
  6. plugins: [
  7. new HtmlWebpackPlugin(
  8. {
  9. template: 'home.html'
  10. }
  11. ),
  12. new BundleAnalyzerPlugin({
  13. analyzerMode: 'static', // 也可以设置为 'server' 或 'disabled'
  14. openAnalyzer: true, // 打开浏览器显示结果
  15. })
  16. ],
  17. output: {
  18. filename: '[name].bundle.js',
  19. path: path.resolve(__dirname, 'dist'),
  20. },
  21. module: {
  22. rules: [
  23. {
  24. test: /\.css$/,
  25. use: ['style-loader', 'css-loader'],
  26. },
  27. {
  28. test: /path\.txt/,
  29. use: ['file-loader'],
  30. },
  31. {
  32. test: /\.(js|jsx)$/,
  33. exclude: /node_modules/,
  34. use: {
  35. loader: 'babel-loader'
  36. }
  37. },
  38. {
  39. test: /\.(png|jp(e*)g|svg|gif)$/,
  40. use: [
  41. {
  42. loader: 'file-loader',
  43. options: {
  44. name: 'images/[hash]-[name].[ext]',
  45. },
  46. },
  47. ],
  48. },
  49. ],
  50. },
  51. resolve: {
  52. extensions: [".js", ".jsx"]
  53. },
  54. mode: 'development',
  55. performance: {
  56. hints: false,
  57. maxEntrypointSize: 512000,
  58. maxAssetSize: 512000
  59. },
  60. devServer:{
  61. compress: false,
  62. port: 9002,
  63. static: './dist',
  64. client:{overlay: false}
  65. },
  66. };