How to serve cdn links for assets in NuxtJS?

末鹿安然 提交于 2020-07-10 12:00:57

问题


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?

Possible ways I can think of:

  1. Vuex Store - set baseURL for the images and then use in components
  2. env - use environment variable to set the cdn URL

TIA


回答1:


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




回答2:


If you have a team working on the project, use Vuex. It save the baseURL in the project itself. Less hassle to copy/share the env variables to the team.



来源:https://stackoverflow.com/questions/53034606/how-to-serve-cdn-links-for-assets-in-nuxtjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!