素材巴巴 > 程序开发 >

webpack5 webpack-cli4

程序开发 2023-09-04 08:32:39

webpack5+webpack-cli4基础搭建

我用到的版本webpack: "5.72.1,webpack-cli:“4.9.2”

  1. 安装webpack+webpack-cli
    npm install webpack webpack-cli
  2. 在文件夹中创建webpack.config.js.
    其实webpack5把entry和output自动封装只需要配置devServer就好了,配置内容如下
module.exports={
 //entry自动封装在src文件下的index.js,output封装为main.jsdevServer:{port:8090,//新建public文件夹,当项目启动时访问的地址为8090,内容为public文件夹下的index.html,如果不配置就会显示Cannot GET /static: {directory: "./public",},}
 }	
 
  1. 文件内容展示如下
//public文件夹下html内容如下
 
 
 Document
 
 1111
 
 
 
 //src文件夹下index.js
 alert(111)
 
  1. 内容展示
    在这里插入图片描述
  2. 配置package.json
{"name": "snabbdom","version": "1.0.0","description": "","main": "index.js",//将scripts内容添加 "dev":"webpack-dev-server""scripts": {"dev":"webpack-dev-server"},"author": "","license": "ISC","dependencies": {"snabbdom": "^3.5.0"},"devDependencies": {"webpack": "^5.72.1","webpack-cli": "^4.9.2","webpack-dev-server": "^4.9.0"}
 }
 
  1. 启动项目npm run dev

标签:

上一篇: angular数值绑定 下一篇:
素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。