当前位置:网站首页>Vite 配置 cdn 加载资源
Vite 配置 cdn 加载资源
2022-07-21 00:05:00 【前端小小白zyw】
一、介绍
上篇文章我们从零配置 Vite + Vue3.0
开发环境、生产环境,本篇文章我们配置 CDN
加载。因为 Vite
不会重写从外部文件导入的内容,我们需要使用支持 ESM
编译的 CDN
。这里我们使用 https://esm.sh/ 来引入相关的第三方库。
二、配置
与 NPM
同步,直接引入对应的包即可,这里我们引入 [email protected]
import {
defineConfig } from 'vite'
export default defineConfig({
resolve: {
// 项目别名
alias: {
'@': resolve(__dirname, '../src'),
'pages': resolve(__dirname, '../src/pages'),
'vue': "https://esm.sh/[email protected]"
},
extensions: ['.js', '.vue', '.json'] // 引入对应的文件时可以忽略其后缀
},
})
导入测试,重启项目:npm run dev
,运行正常
但是我修改热加载的内容,发现热加载失效,控制台报错:__VUE_HMR_RUNTIME__ is not defined
查阅文档,这里是因为我们引入生产环境的包,缺少热加载相关的代码,这里我们换成开发环境的包,文档里面明确说明:需要在后面拼接?dev
resolve: {
// 项目别名
alias: {
'@': resolve(__dirname, '../src'),
'pages': resolve(__dirname, '../src/pages'),
'vue': "https://esm.sh/[email protected]?dev",
},
extensions: ['.js', '.vue', '.json'] // 引入对应的文件时可以忽略其后缀
}
重启,完美解决,热加载生效,问题解决
至此,Vite
配置 CDN
告以段落
三、相关文章
边栏推荐
- 王者荣耀商城异地多活部署设计
- 30岁被公司裁员,有人从此一蹶不振,而我逆风翻盘,重获新生~
- Thread of C (41)
- 471-82(647、5、92、143、148、19)
- PHP FPM custom ZABBIX monitoring
- 从一线开发到技术总监,你就差一个赶鸭子上架
- Starbucks CEO said that more stores may be closed to ensure the safety of employees
- At the age of 30, I was laid off by the company, and some people never recovered, but I turned against the wind and was reborn~
- What have I experienced to become a harder tester than development?
- C#(三十三)之路径(Path)
猜你喜欢
[CS231N]Notes_1-Introduction
ICML 2022 | tutorial validity, reliability and significance: a statistical method tutorial for reproducible machine learning
【精选】Mysql B-Tree和B+Tree的结构?
Hands on moveit2 | introduction and installation
Design of online blog system
Redis(主从复制、哨兵模式、集群)概述及部署
Super milk's note taking software: obsidain
ICML 2022 | 教程效度,可靠性和意义:可复现机器学习的统计方法教程
Sycl learning notes
212. 单词搜索 II
随机推荐
The latest method: set the href of a tag in electron development, jump to the default browser, and open the link
VMware下配置kali(一)
Ora-01461: only the long value to be inserted into the long column can be bound
openresty ngx. CTX request context
C (37) FileStream
数学建模 - K-means聚类
【OpenCV】solvePnPRansac /solvePnP 计算外参数,求解相机位姿
How to analyze and design performance test scenarios
Code之模拟
yarn run dev 无法加载文件 C:\Program Files\nodejs\node_global\yarn.ps1,因为在此系统中禁止执行脚本
The transport layer uses a web proxy to access websites
redis 实现分布式全局唯一id
IP第十一天笔记
6条shell小技巧,让脚本显得不再业余
ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值
下游任务(downstream task)含义
Jianghu nickname of Chinese Universities
RuntimeError: CUDA out of memory. Tried to allocate 32.00 MIB | view GPU memory
Math.abs一定大于等于0吗?
At the age of 30, I was laid off by the company, and some people never recovered, but I turned against the wind and was reborn~