Background
It should be possible to host generated assets on a CDN, and this should be possible to configure at runtime via Nitro. If omitted, assets should be served from the Nitro static middleware.
Related issues: #12612, #12922
Asset types
There are two kinds of assets we serve from Nitro:
- static assets originally from the
public/ folder that are not the product of the build
- build outputs. As a matter of best practice these should be located in a separate folder so we can apply different caching rules
Proposed configuration
Instead of attempting to configure all of this through router.base and build.publicPath, it makes sense to configure it with the following three values:
- basePath:
/
- buildAssetsPath:
/_nuxt
- cdnURL?
export default defineNuxtConfig({
// nuxtApp configuration
app: {
basePath, // Relative to ./
buildAssetsPath, // Relative to basePath
cdnURL? // Absolute URL
}
})
Runtime
At runtime the following values will be calculated, allowing for dynamic override via Nitro (or within server):
getRouterBase() - returns the vue router base which should be prepended to all paths for client-side navigation
computed: basePath
getPublicAssetsURL() - returns the public URL that corresponds to .output/public - which might be a CDN URL or the router base
computed: cdnURL || basePath
getBuildAssetsURL() - returns the full computed path to the _nuxt folder that serves build assets
computed: cdnURL ? ${cdnURL}/${assetsPath} : ${basePath/${assetsPath}
Background
It should be possible to host generated assets on a CDN, and this should be possible to configure at runtime via Nitro. If omitted, assets should be served from the Nitro static middleware.
Related issues: #12612, #12922
Asset types
There are two kinds of assets we serve from Nitro:
public/folder that are not the product of the buildProposed configuration
Instead of attempting to configure all of this through
router.baseandbuild.publicPath, it makes sense to configure it with the following three values://_nuxtRuntime
At runtime the following values will be calculated, allowing for dynamic override via Nitro (or within server):
getRouterBase()- returns the vue router base which should be prepended to all paths for client-side navigationcomputed:
basePathgetPublicAssetsURL()- returns the public URL that corresponds to.output/public- which might be a CDN URL or the router basecomputed:
cdnURL || basePathgetBuildAssetsURL()- returns the full computed path to the_nuxtfolder that serves build assetscomputed:
cdnURL ? ${cdnURL}/${assetsPath} : ${basePath/${assetsPath}