Nuxt Inferred Targets

In Nx version 17.3, the @nx/nuxt plugin can create inferred tasks for projects that have a Nuxt configuration file present. This means you can run nx build my-project, nx serve my-project and nx test my-project for that project, even if there is no build, serve or test targets defined in package.json or project.json.

Setup

To enable inferred targets, add @nx/nuxt/plugin to the plugins array in nx.json.

nx.json
1{ 2 "plugins": [ 3 { 4 "plugin": "@nx/nuxt/plugin", 5 "options": { 6 "buildTargetName": "build", 7 "testTargetName": "test", 8 "serveTargetName": "serve" 9 } 10 } 11 ] 12} 13
Nx 15 and lower use @nrwl/ instead of @nx/

Target Inference Process

Identify Valid Projects

The @nx/nuxt/plugin plugin will create a target for any project that has a Nuxt configuration file present. Any of the following files will be recognized as a Nuxt configuration file:

  • nuxt.config.js
  • nuxt.config.ts
  • nuxt.config.mjs
  • nuxt.config.mts
  • nuxt.config.cjs
  • nuxt.config.cts

Name the Inferred Target

Once a Nuxt configuration file has been identified, the targets are created with the name you specify under buildTargetName, serveTargetName or testTargetName in the nx.json plugins array. The default names for the inferred targets are build, serve and test.

Set Inferred Options

The @nx/nuxt/plugin plugin will start with any targetDefaults you have set in nx.json, and then apply the following properties:

For build

PropertySample ValueDescription
commandnuxi buildBuild the project
cachetrueAutomatically cache the task
inputsproductionBreak the cache if non-test files in the project change
inputs{ externalDependencies: [ "nuxi" ] }Break the cache if the version of the nuxi package changes
outputs["{workspaceRoot}/dist/my-project"]The output directory of the build - read from the Nuxt configuration file

For serve

PropertySample ValueDescription
commandnuxi devServe the project

Debug Inferred Targets

To view the final output of an inferred target you can use the nx show project my-project command or use Nx Console. The result should look something like this:

1{ 2 "targets": { 3 "build": { 4 "cache": true, 5 "dependsOn": ["^build"], 6 "inputs": [ 7 "production", 8 "^production", 9 { 10 "externalDependencies": ["nuxi"] 11 } 12 ], 13 "options": { 14 "cwd": "my-project", 15 "command": "nuxi build" 16 }, 17 "outputs": ["{workspaceRoot}/dist/my-project"], 18 "executor": "nx:run-commands", 19 "configurations": {} 20 }, 21 "serve": { 22 "options": { 23 "cwd": "my-project", 24 "command": "nuxi dev" 25 }, 26 "executor": "nx:run-commands", 27 "configurations": {} 28 } 29 } 30} 31

You can also use the nx show project my-project command with the --json false flag to see a concise output of the inferred targets:

1Name: my-project 2Root: my-project 3Source Root: my-project/src 4Tags: 5Implicit Dependencies: 6Targets: 7- build: nx:run-commands 8- serve: nx:run-commands 9