Azure 静态 Web 应用旨在通过GitHub Actions 工作流进行持续部署。默认情况下,Nuxt 会检测此部署环境以启用 azure 预设。
安装Azure Functions Core Tools如果您想在本地进行测试。
您可以在部署前调用开发环境进行预览。
npx nuxi build --preset=azure
npx @azure/static-web-apps-cli start .output/public --api-location .output/server
Azure 静态 Web 应用使用 staticwebapp.config.json 文件配置。
每当使用 azure 预设构建应用程序时,Nuxt 都会自动生成此配置文件。
它根据以下条件添加以下属性
| 属性 | 条件 | 默认 |
|---|---|---|
| platform.apiRuntime | 将根据您的包配置自动设置为 node:16 或 node:14。 | node:16 |
| navigationFallback.rewrite | 始终为 /api/server | /api/server |
| 路由 | 所有预渲染路由都已添加。此外,如果您没有 index.html 文件,则会为您创建一个空文件以实现兼容性,并且对 /index.html 的请求将重定向到由 /api/server 处理的根目录。 | [] |
您可以使用 azure.config 选项更改生成的配置。例如,如果您想为 Azure 函数指定 Node 运行时,请将 nuxt.config.ts 文件编辑为以下内容
export default defineNuxtConfig({
// ...
nitro: {
azure: {
config: {
// ...
platform: {
apiRuntime: 'node:18'
}
}
}
}
})
自定义路由将首先添加和匹配。如果发生冲突(由对象是否具有相同的路由属性决定),自定义路由将覆盖生成的路由。
当您将 GitHub 存储库链接到 Azure 静态 Web 应用时,工作流文件会添加到存储库中。
当您被要求选择框架时,请选择自定义并提供以下信息
| 输入 | 值 |
|---|---|
| app_location | '/' |
| api_location | '.output/server' |
| output_location | '.output/public' |
如果您跳过了此步骤,您始终可以在工作流中找到构建配置部分并更新构建配置
###### Repository/Build Configurations ######
app_location: '/'
api_location: '.output/server'
output_location: '.output/public'
###### End of Repository/Build Configurations ######
如果您正在使用 runtimeConfig,您可能需要配置相应的Azure 上的环境变量.