问题
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:
- Vuex Store - set baseURL for the images and then use in components
- 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