Skip to content

Commit

Permalink
feat(nuxt): nodes for build, serve targets
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Nov 29, 2023
1 parent 2c88282 commit ecba82e
Show file tree
Hide file tree
Showing 36 changed files with 859 additions and 618 deletions.
84 changes: 84 additions & 0 deletions docs/shared/packages/nuxt/nuxt-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,87 @@ pnpm install -D @nx/nuxt
```shell
nx g @nx/nuxt:app my-app
```

## Add Nx to existing Nuxt applications

Using the `@nx/nuxt/plugin`, you can adds Nuxt targets to Nx. This allows you to run Nuxt for projects that have a `nuxt.config.ts` file via Nx with caching and everything setup.

### How it works

#### Fist, set up Nx

First, you need to run `npx nx init` in your project. You can read more in our guide about [adopting Nx](/recipes/adopting-nx/adding-to-existing-project).

#### Then, add the plugin

Install the plugin as shown above:

{% tabs %}
{% tab label="npm" %}

```shell
npm install -D @nx/nuxt
```

{% /tab %}
{% tab label="yarn" %}

```shell
yarn add -D @nx/nuxt
```

{% /tab %}
{% tab label="pnpm" %}

```shell
pnpm install -D @nx/nuxt
```

{% /tab %}
{% /tabs %}

#### Finally, run the init command

You can now run `nx g @nx/nuxt:init` and the following will be setup in `nx.json` in the `plugins` array:

```json
...
plugins: [
{
"plugin": "@nx/nuxt/plugin",
"options": {
"buildTargetName": "build",
"serveTargetName": "serve",
"testTargetName": "test",
},
},
...
]
```

This will create targets for `build`, `test` and `serve` in your project graph, so that you can run `nx build my-app`, `nx test my-app` etc. This will work for every single project in your workspace that has a `nuxt.config.ts` file.

### How to configure

Any options you need for your Nuxt app, you can add in your project's `nuxt.config.ts`.

If you want to customize these targets more, read the [guide on configuring projects](/reference/project-configuration).

You can edit the name of your targets if you want to use a different name. For example, you can have this configuration:

```json
...
plugins: [
{
"plugin": "@nx/nuxt/plugin",
"options": {
"buildTargetName": "build-core",
"serveTargetName": "serve",
"testTargetName": "test",
},
},
...
]
```

and this will create `build-core` and `serve` targets in your project graph. You can then call `nx build-core my-app` for all your projects that have a `nuxt.config.ts|js` file.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
"@nestjs/schematics": "^9.1.0",
"@nestjs/swagger": "^6.0.0",
"@nestjs/testing": "^9.0.0",
"@nuxt/kit": "^3.8.1",
"@ngrx/effects": "~17.0.0",
"@ngrx/router-store": "~17.0.0",
"@ngrx/store": "~17.0.0",
"@nuxt/kit": "^3.8.1",
"@nuxt/schema": "^3.8.1",
"@nx/angular": "17.1.1",
"@nx/cypress": "17.1.1",
Expand Down Expand Up @@ -230,7 +230,7 @@
"ng-packagr": "~17.0.0",
"node-fetch": "^2.6.7",
"npm-package-arg": "11.0.1",
"nuxi": "npm:nuxi-nightly@3.9.2-1699007958.251cab5",
"nuxi": "^3.10.0",
"nx": "17.1.1",
"octokit": "^2.0.14",
"open": "^8.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as path from 'path';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
export default defineConfig({
root: __dirname,
cacheDir: '../node_modules/.vite/my-lib',
plugins: [
Expand All @@ -27,6 +28,7 @@ export default defineConfig({
// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
outDir: '../dist/my-lib',
lib: {
// Could also be a dictionary or array of multiple entry points.
entry: 'src/index.ts',
Expand All @@ -49,6 +51,11 @@ export default defineConfig({
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
coverage: {
reportsDirectory: '../coverage/my-lib',
provider: 'v8',
},
},
});
"
Expand Down
3 changes: 1 addition & 2 deletions packages/nuxt/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"nx",
"typescript",
"@nx/cypress",
"@nx/playwright",
"nuxi"
"@nx/playwright"
]
}
]
Expand Down
5 changes: 0 additions & 5 deletions packages/nuxt/executors.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"executors": {
"build": {
"implementation": "./src/executors/build/build.impl",
"schema": "./src/executors/build/schema.json",
"description": "Build with Nuxt."
},
"serve": {
"implementation": "./src/executors/serve/serve.impl",
"schema": "./src/executors/serve/schema.json",
Expand Down
3 changes: 1 addition & 2 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
"migrations": "./migrations.json"
},
"dependencies": {
"nuxi": "npm:nuxi-nightly@3.9.2-1699007958.251cab5",
"nuxi": "^3.10.0",
"tslib": "^2.3.0",
"@nuxt/kit": "^3.8.1",
"@nuxt/schema": "^3.8.1",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@nx/eslint": "file:../eslint",
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { createNodes, NuxtPluginOptions } from './src/plugins/plugin';
3 changes: 2 additions & 1 deletion packages/nuxt/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"main": "packages/nuxt/index.ts",
"generateExportsField": true,
"additionalEntryPoints": [
"{projectRoot}/{executors,generators,migrations}.json"
"{projectRoot}/{executors,generators,migrations}.json",
"{projectRoot}/plugin.ts"
],
"assets": [
{
Expand Down
40 changes: 0 additions & 40 deletions packages/nuxt/src/executors/build/build.impl.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/nuxt/src/executors/build/compat.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/nuxt/src/executors/build/schema.d.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/nuxt/src/executors/build/schema.json

This file was deleted.

8 changes: 0 additions & 8 deletions packages/nuxt/src/executors/serve/schema.d.ts

This file was deleted.

35 changes: 1 addition & 34 deletions packages/nuxt/src/executors/serve/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,7 @@
"keys": []
}
],
"properties": {
"debug": {
"type": "boolean",
"description": "Set to true to enable debug mode."
},
"dev": {
"type": "boolean",
"description": "Whether Nuxt is running in development mode."
},
"ssr": {
"type": "boolean",
"description": "Whether to enable rendering of HTML - either dynamically (in server mode) or at generate time. If set to false generated pages will have no content."
},
"port": {
"type": "number",
"description": "Port to listen on.",
"x-priority": "important"
},
"host": {
"description": "Hostname of the server.",
"type": "string"
},
"https": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "object"
}
],
"description": "Listen with https protocol with a self-signed certificate by default."
}
},
"properties": {},
"definitions": {},
"required": []
}

0 comments on commit ecba82e

Please sign in to comment.