analogjs / analog

The fullstack meta-framework for Angular. Powered by Vite and Nitro
https://analogjs.org
MIT License
2.57k stars 245 forks source link

Feature: update build directory if preset is Vercel #491

Closed brandonroberts closed 1 year ago

brandonroberts commented 1 year ago

Which scope/s are relevant/related to the feature request?

vite-plugin-nitro

Information

Analog supports deploying to Vercel through a client-only app or SSR app deployed as a Vercel function.

If you want to deploy a fullstack app, you need to adjust the output directory to use Vercel's Build Output API, which is located in the .vercel directory at the root of the workspace.

Here's an example repo https://github.com/brandonroberts/analog-angular-vercel-example

We should adjust the output directory internally if the deployment provider is Vercel so it can be a low config deployment

Describe any alternatives/workarounds you're currently using

Adjust the build output in the Vite config

/// <reference types="vitest" />

import analog from '@analogjs/platform';
import { defineConfig, splitVendorChunkPlugin } from 'vite';
import tsConfigPaths from 'vite-tsconfig-paths';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  return {
    publicDir: 'src/public',
    optimizeDeps: {
      include: ['@angular/common', '@angular/forms'],
    },
    build: {
      target: ['es2020'],
    },
    plugins: [
      analog({
        nitro: {
          output: {
            dir: '../../../.vercel/output', // <- Vercel output
            publicDir: '../../../.vercel/output/static', // <- Vercel output
          },
        },
      }),
      tsConfigPaths({
        root: '../',
      }),
      splitVendorChunkPlugin(),
    ],
    test: {
      globals: true,
      environment: 'jsdom',
      setupFiles: ['src/test-setup.ts'],
      include: ['**/*.spec.ts'],
      cache: {
        dir: `../node_modules/.vitest`,
      },
    },
    define: {
      'import.meta.vitest': mode !== 'production',
    },
  };
});

I would be willing to submit a PR to fix this issue

goetzrobin commented 1 year ago

@brandonroberts I can work on this 💪