webpack.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const path = require("path");
  2. const HtmlWebpackPlugin = require("html-webpack-plugin");
  3. module.exports = {
  4. mode:"production",
  5. // development是开发模式
  6. // node无
  7. // production 生产模式
  8. // entry:"", 单个入口 默认index.js
  9. // 注意清dist
  10. // 对象写法
  11. // entry:{
  12. // text:"./src/text.js",
  13. // text2:"./src/text2.js"
  14. // },
  15. // 数组写法
  16. // entry:[
  17. // "./src/text.js",
  18. // "./src/text2.js"
  19. // ],
  20. output:{
  21. // filename:"file.js", //指定打包后的文件名称
  22. clean:true, //自动删除旧的文件,生成新的打包文件
  23. // path:path.resolve(__dirname,"hello") , //指定打包后的文件 hello文件夹(自己创建的已有的文件夹)
  24. // 如果有多个文件
  25. // filename:"[name.js]" //此时entry用对象写法,数组写法容易合并只生成一个文件
  26. },
  27. module:{
  28. rules:[
  29. {
  30. test:/\.css$/, //匹配正则
  31. use:[
  32. {loader:"style-loader"},
  33. {loader:"css-loader"},
  34. ] //执行顺序是先后往前,先css转换在style展示
  35. }
  36. ]
  37. },
  38. plugins: [new HtmlWebpackPlugin({
  39. title: "打包工具webpack",
  40. })],
  41. }