Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vite-plugin-nitro): add internal deployment support for Netlify #1202

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions apps/docs-app/docs/features/deployment/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ Analog supports deploying on [Netlify](https://netlify.com/) with minimal config

<Tabs groupId="porject-type">
<TabItem label="Create analog" value="create-analog">
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.
</TabItem>

<TabItem label="Nx" value="nx">
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.

Expand All @@ -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"
```

</TabItem>
Expand Down
17 changes: 17 additions & 0 deletions packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we need to do here is set the serverDir. The dir sets the output for everything else, including the publicDir and .nitro build directory.

Suggested change
dir: '{{ rootDir }}/.netlify/functions-internal',
serverDir: '{{ rootDir }}/.netlify/functions-internal',

},
});
Loading