[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
一、webpack的使用:
项目结构:
src:源码
dist:打包后的文件,用于发布的文件(bundle.js就是打包后的文件,然后在index.html引用即可)
同cmd进行项目打包:
打包完,在项目dist目录下就会生成一个打包文件bundle.js文件,在运行页调用此js文件,运行结果:
PS:只需打包入口函数(只打包main.js),其他依赖类会自动打包
有两种开发模式CommonJS、ES6两种模块化开发:
ES6:
引用:
重新打包后运行情况:
二、webpack.config.js配置和package.json :
在配置文件的时候,需要node.js的环境,在项的目录下初始化环境:npm init,生成package.json配置文件
生成package.json:
PS:"license": "ISC" 如果不是开源的,则可以删除句话。
安装依赖:npm install
webpack.config.js配置:出口入口配置好后,在项目目录下,直接输入webpack就可以进行打包了,省去一些文件的路径了,因为路径都配置在此文件里面了:
npm run build = webpack 对等起来,自定义启动命令:
运行并测试成功:
三、局部安装webpack
:给本项目配置webpack的环境,在打包时,会先找本项目的环境,未找到才会去找系统的环境,一般情况下,项目都会用自己的环境进行打包,用开发时依赖进行安装:cnpm
install [email protected] --save-dev
局部安装完后,在idea的终端执行 npm run build
时就用的是本项目的webpack环境,优先找局部的webpack环境,如果有就不会再调用全局变量的webpack;否则才去调用全局变量的webpack环境。