From ade5fdd8e17205dd56afe6ca4f6641851c93cb55 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Wed, 3 Jul 2024 13:39:53 +0200 Subject: [PATCH 1/2] feat(vite-plugin-nitro): add internal deployment support for Netlify --- .../src/lib/vite-plugin-nitro.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts b/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts index 0203c80b6..1619df1fb 100644 --- a/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts +++ b/packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts @@ -132,6 +132,10 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] { nitroConfig = withCloudflareOutput(nitroConfig); } + if (isNetlifyPreset(buildPreset)) { + nitroConfig = withNetlifyOutput(nitroConfig); + } + if (!ssrBuild && !isTest) { // store the client output path for the SSR build config clientOutputPath = resolve( @@ -368,3 +372,16 @@ const withCloudflareOutput = (nitroConfig: NitroConfig | undefined) => ({ serverDir: '{{ output.publicDir }}/_worker.js', }, }); + +const isNetlifyPreset = (buildPreset: string | undefined) => + process.env['NETLIFY'] || + process.env['NETLIFY_LOCAL'] || + (buildPreset && buildPreset.toLowerCase().includes('netlify')); + +const withNetlifyOutput = (nitroConfig: NitroConfig | undefined) => ({ + ...nitroConfig, + output: { + ...nitroConfig?.output, + dir: '{{ rootDir }}/.netlify/functions-internal', + }, +}); From 2dade9b5021345de51dbcdaa636c7b02754b7f25 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Wed, 3 Jul 2024 13:43:02 +0200 Subject: [PATCH 2/2] docs: update Netlify deployment setup instructions --- apps/docs-app/docs/features/deployment/providers.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/docs-app/docs/features/deployment/providers.md b/apps/docs-app/docs/features/deployment/providers.md index 91141392b..e2f545e59 100644 --- a/apps/docs-app/docs/features/deployment/providers.md +++ b/apps/docs-app/docs/features/deployment/providers.md @@ -13,14 +13,13 @@ Analog supports deploying on [Netlify](https://netlify.com/) with minimal config -In the build settings of your Netlify project, set the [publish directory](https://docs.netlify.com/configure-builds/overview/#definitions) to `dist/analog/public` to deploy the static assets and the [functions directory](https://docs.netlify.com/configure-builds/overview/#definitions) to `dist/analog` to deploy the server. +In the build settings of your Netlify project, set the [publish directory](https://docs.netlify.com/configure-builds/overview/#definitions) to `dist/analog/public` to deploy the static assets. In the build settings of your Netlify project on the web UI, do the following. 1. Set the [build command](https://docs.netlify.com/configure-builds/overview/#definitions) to `nx build [your-project-name]` 2. Set the [publish directory](https://docs.netlify.com/configure-builds/overview/#definitions) to `dist/[your-project-name]/analog/public` to deploy the static assets -3. Set the [functions directory](https://docs.netlify.com/configure-builds/overview/#definitions) to `dist/[your-project-name]/analog` to deploy the server. You can also configure this by putting a `netlify.toml` at the root of your repository. Below is an example config. @@ -29,7 +28,6 @@ You can also configure this by putting a `netlify.toml` at the root of your repo [build] command = "nx build my-analog-app" publish = "dist/my-analog-app/analog/public" - functions = "dist/my-analog-app/analog" ```