Movatterモバイル変換


[0]ホーム

URL:


Skip to content
NxNxDocs
ContactTry Nx Cloud for free
GitHubYouTubeXDiscord

In your application'snuxt.config.ts file, ensure that thenitro property is configured to use thevercel preset, and that theoutput.dir property is set to the appropriate directory. The directory that Vercel expects to find the application's build output (as explained in theVercel documentation) in is.vercel/output at the root of the repository/workspace. So, if your application is located atapps/my-app then theoutput.dir property should be set to../../.vercel/output.

For example, if your Nx workspace is structured like this:

  • Directoryapps/
    • Directorymy-app/
      • nuxt.config.ts
      • Directorysrc/
      • tsconfig.app.json
      • tsconfig.json
      • tsconfig.spec.json
  • nx.json
  • package-lock.json
  • package.json
  • tsconfig.base.json

Then yournitro configuration should look like this:

apps/my-app/nuxt.config.ts
nitro: {
preset:'vercel',
output:{
dir:'../../.vercel/output'
}
},

For Vercel deployment, it does not really matter what thebuildDir property in yournuxt.config.ts is set to.

So, your entirenuxt.config.ts file may look something like this:

apps/my-app/nuxt.config.ts
import { nxViteTsPaths }from'@nx/vite/plugins/nx-tsconfig-paths.plugin';
import { defineNuxtConfig }from'nuxt/config';
exportdefaultdefineNuxtConfig({
workspaceDir:'../../',
srcDir:'src',
devtools: { enabled:true },
buildDir:'../../dist/apps/my-app/.nuxt',
devServer: {
host:'localhost',
port:4200,
},
typescript: {
typeCheck:true,
tsConfig: {
extends:'./tsconfig.app.json',
},
},
imports: {
autoImport:false,
},
css: ['~/assets/css/styles.css'],
vite: {
plugins: [nxViteTsPaths()],
},
nitro: {
preset:'vercel',
output: {
dir:'../../.vercel/output',
},
},
});

Configure your Vercel project's settings appropriately

Section titled “Configure your Vercel project's settings appropriately”
  1. If you are "importing" your Nx workspace's repository for the first time, make sure you donot choose a root directory as part of the repo selection process (therefore leaving it to be the root of the full repo/workspace)
  2. Ensure the Nuxt.js "Framework Preset" is selected
  3. Expand the "Build & Development Settings" and toggle the override switch for the build command. For example, for an application namedmy-app the value will look like this:
npxnxbuildmy-app--prod

New Vercel Project

If you have an existing project on Vercel then the exact same guidance applies as for the section above, it's just that you will need to update the project's existing settings.

When everything is updated appropriately, for ourmy-app example we would see the following in our "General" settings UI:

Existing Vercel Project

Skipping build if the application is not affected

Section titled “Skipping build if the application is not affected”

One of the core features of Nx is to run code quality checks and builds only for projects that are affected by recent code changes. We can useVercel's ignored build step feature to only build our application if it is affected.

To build only what's affected, use thenpx nx-ignore <app-name> command underProject Settings > Git on Vercel.

Ignore build step

Thenx-ignore command uses Nx to detect whether the current commit affects the specified app, and will skip the build if it is not affected.

Naturally, you can continue on and set any additional Environment Variables etc that may be appropriate for your projects, but we have now covered the key points needed to deploy Nuxt.js projects from Nx workspaces on Vercel!


[8]ページ先頭

©2009-2025 Movatter.jp