webpack5 webpack-cli4
程序开发
2023-09-04 08:32:39
webpack5+webpack-cli4基础搭建
我用到的版本webpack: "5.72.1,webpack-cli:“4.9.2”
- 安装webpack+webpack-cli
npm install webpack webpack-cli - 在文件夹中创建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",},}
}
- 文件内容展示如下
//public文件夹下html内容如下
Document
1111
//src文件夹下index.js
alert(111)
- 内容展示
- 配置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"}
}
- 启动项目npm run dev
标签:
上一篇:
angular数值绑定
下一篇:
相关文章
-
无相关信息