当前位置: 首页 > 文档资料 > Next.js 中文文档 >

CDN 支持前缀

优质
小牛编辑
122浏览
2023-12-01

建立一个 CDN,你能配置assetPrefix选项,去配置你的 CDN 源。

const isProd = process.env.NODE_ENV === 'production'
module.exports = {
  // You may only need to add assetPrefix in the production.
  assetPrefix: isProd ? 'https://cdn.mydomain.com' : ''
}

注意:Next.js 运行时将会自动添加前缀,但是对于/static是没有效果的,如果你想这些静态资源也能使用 CDN,你需要自己添加前缀。有一个方法可以判断你的环境来加前缀,如 in this example。