webpack.config.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. module.exports = {
  4. mode: 'production',
  5. entry: './src/b.js',
  6. // entry: ['./src/a.js', './src/b.js'],
  7. // entry: {
  8. // hi:'./src/b.js',
  9. // ha:'./src/a.js'
  10. // }
  11. output: {
  12. // clean: true, // 清楚打包文件中的其他文件
  13. filename:'[name]-[id]-[hash].js', //输出文件名字
  14. // path:path.resolve(__dirname,'news') // 打包文件夹输出
  15. },
  16. module: {
  17. rules: [
  18. {
  19. test: /\.css$/i,
  20. use: ['style-loader', 'css-loader'],
  21. },
  22. {
  23. test: /\.(png|svg|jpg|jpeg|gif)$/i,
  24. type: 'asset/resource',
  25. },
  26. {
  27. test: /\.m?js$/,
  28. exclude: /(node_modules|bower_components)/,
  29. use: {
  30. loader: 'babel-loader',
  31. options: {
  32. presets: ['@babel/preset-env'],
  33. },
  34. },
  35. },
  36. ],
  37. },
  38. plugins: [new HtmlWebpackPlugin({ template: './src/index.html' })],
  39. // devtool: 'inline-source-map'
  40. }