如何在 NuxtJS 中为资产提供 CDN 链接? [英] How to serve cdn links for assets in NuxtJS?
本文介绍了如何在 NuxtJS 中为资产提供 CDN 链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 NUXTJ 来创建服务器端呈现的网站.我的问题是,虽然在 nuxt 项目结构中有一个 assets/static 文件夹来提供图像&静态文件,我想为我的所有图像源设置 cdn 链接.这样做的最佳方法是什么?
I am working on a NUXTJs to create server side rendered website. My question is that although there is a assets/static folder in nuxt project structure to serve images & static files, i want to set cdn link for all my image source. What would be the best approach to do that?
我能想到的可能方法:
- Vuex Store - 为图像设置 baseURL,然后在组件中使用
- env - 使用环境变量设置 cdn URL
TIA
推荐答案
可以通过nuxt.config中的publicPath属性设置
You can set it via publicPath property in nuxt.config
export default {
build: {
publicPath: 'https://cdn.nuxtjs.org'
}
}
https://nuxtjs.org/api/configuration-build/#publicpath一个>
这篇关于如何在 NuxtJS 中为资产提供 CDN 链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文