Skip to content

Commit

Permalink
feat(nuxt): strip down executors and config
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Nov 29, 2023
1 parent dd716db commit 042f873
Show file tree
Hide file tree
Showing 46 changed files with 29,342 additions and 671 deletions.
7 changes: 0 additions & 7 deletions docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2173,13 +2173,6 @@
"name": "Overview of the Nx Nuxt Plugin",
"description": "The Nx Plugin for Nuxt contains generators for managing Nuxt applications within a Nx workspace. This page also explains how to configure Nuxt on your Nx workspace.",
"file": "shared/packages/nuxt/nuxt-plugin"
},
{
"id": "nuxt-nodes-plugin",
"path": "/nx-api/nuxt-nodes-plugin",
"name": "Overview of the @nx/nuxt/plugin",
"description": "The @nx/nuxt/plugin adds Nuxt targets/projects to the Nx project graph. This allows you to run Nuxt for projects that have a nuxt.config.ts file without creating a project.json file.",
"file": "shared/packages/nuxt/nuxt-nodes-plugin"
}
]
},
Expand Down
60 changes: 0 additions & 60 deletions docs/shared/packages/nuxt/nuxt-nodes-plugin.md

This file was deleted.

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.
49 changes: 0 additions & 49 deletions e2e/nuxt/src/nuxt-pcv3.test.ts

This file was deleted.

20 changes: 20 additions & 0 deletions e2e/nuxt/src/nuxt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ import {
uniq,
} from '@nx/e2e/utils';

// jest.mock('@nuxt/kit', () => ({
// loadNuxtConfig: jest.fn().mockImplementation(() => {
// return Promise.resolve({
// path: 'nuxt.config.ts',
// config: {},
// dependencies: [],
// });
// }),
// }));

// jest.mock('@nx/nuxt', () => ({
// loadNuxtKitDynamicImport: jest.fn().mockResolvedValue({
// loadNuxtConfig: jest.fn().mockResolvedValue({
// path: 'nuxt.config.ts',
// config: {},
// dependencies: [],
// }),
// }),
// }));

describe('Nuxt Plugin', () => {
let proj: string;
const app = uniq('app');
Expand Down
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 @@ -49,6 +49,10 @@ export default defineConfig({
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
coverage: {
reportsDirectory: '../coverage/my-lib',
},
},
});
"
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
41 changes: 0 additions & 41 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.

0 comments on commit 042f873

Please sign in to comment.