-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vite): nodes for build, serve, test, preview targets
- Loading branch information
Showing
32 changed files
with
1,252 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
docs/generated/packages/vite/documents/vite-nodes-plugin.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: Overview of the @nx/vite/plugin | ||
description: The @nx/vite/plugin adds Vite targets/projects to the Nx project graph. This allows you to run Vite for projects that have a vite.config.ts file without creating a project.json file. | ||
--- | ||
|
||
{% callout type="note" title="Still in beta" %} | ||
This feature is still in beta. To use it you must have the `NX_PCV3` environment variable set to `"true"`. | ||
{% /callout %} | ||
|
||
## What is the @nx/vite/plugin? | ||
|
||
The `@nx/vite/plugin` adds Vite targets/projects to the Nx project graph. This allows you to run Vite for projects that have a `vite.config.ts` file without creating a `project.json` file. | ||
|
||
This is an effort to reduce duplicate code and configurations for your projects that use Vite. | ||
|
||
## How it works | ||
|
||
The `@nx/vite:init` generator (which is called through the `@nx/vite:configuration` generator, and the `@nx/react:app|lib`, `@nx/vue:app|lib` and `@nx/web:app|lib` generators) the following entry is added in the `plugins` array of your `nx.json`: | ||
|
||
```json | ||
... | ||
plugins: [ | ||
{ | ||
"plugin": "@nx/vite/plugin", | ||
"options": { | ||
"buildTargetName": "build", | ||
"previewTargetName": "preview", | ||
"serveTargetName": "serve", | ||
"testTargetName": "test", | ||
"serveStaticTargetName": "static-serve", | ||
}, | ||
}, | ||
... | ||
] | ||
``` | ||
|
||
This will create targets for `build`, `preview`, `test` and `serve` in your project graph, so that you can run `nx build my-app`, `nx test my-app` etc, without manually defining these targets in each of your projects' `project.json` files. This will work for every single project in your workspace that has a `vite.config.ts|js` file. | ||
|
||
## How to configure | ||
|
||
The plugin generates these targets with bare minimum (no extra) options configuration. Any options you need for your Vite app, you can add in your project's `vite.config.ts`. | ||
|
||
If you want to add some universal options for all your `build` targets, for example, you can still do so in the [`targetDefaults`](/recipes/running-tasks/reduce-repetitive-configuration#reduce-configuration-with-targetdefaults). | ||
|
||
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/vite/plugin", | ||
"options": { | ||
"buildTargetName": "build-core", | ||
"previewTargetName": "preview", | ||
"serveTargetName": "serve", | ||
"testTargetName": "test", | ||
"serveStaticTargetName": "static-serve", | ||
}, | ||
}, | ||
... | ||
] | ||
``` | ||
|
||
and this will create `build-core`, `preview`, `test` and `serve` targets in your project graph. You can then call `nx build-core my-app` for all your projects that have a `vite.config.ts|js` file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: Overview of the @nx/vite/plugin | ||
description: The @nx/vite/plugin adds Vite targets/projects to the Nx project graph. This allows you to run Vite for projects that have a vite.config.ts file without creating a project.json file. | ||
--- | ||
|
||
{% callout type="note" title="Still in beta" %} | ||
This feature is still in beta. To use it you must have the `NX_PCV3` environment variable set to `"true"`. | ||
{% /callout %} | ||
|
||
## What is the @nx/vite/plugin? | ||
|
||
The `@nx/vite/plugin` adds Vite targets/projects to the Nx project graph. This allows you to run Vite for projects that have a `vite.config.ts` file without creating a `project.json` file. | ||
|
||
This is an effort to reduce duplicate code and configurations for your projects that use Vite. | ||
|
||
## How it works | ||
|
||
The `@nx/vite:init` generator (which is called through the `@nx/vite:configuration` generator, and the `@nx/react:app|lib`, `@nx/vue:app|lib` and `@nx/web:app|lib` generators) the following entry is added in the `plugins` array of your `nx.json`: | ||
|
||
```json | ||
... | ||
plugins: [ | ||
{ | ||
"plugin": "@nx/vite/plugin", | ||
"options": { | ||
"buildTargetName": "build", | ||
"previewTargetName": "preview", | ||
"serveTargetName": "serve", | ||
"testTargetName": "test", | ||
"serveStaticTargetName": "static-serve", | ||
}, | ||
}, | ||
... | ||
] | ||
``` | ||
|
||
This will create targets for `build`, `preview`, `test` and `serve` in your project graph, so that you can run `nx build my-app`, `nx test my-app` etc, without manually defining these targets in each of your projects' `project.json` files. This will work for every single project in your workspace that has a `vite.config.ts|js` file. | ||
|
||
## How to configure | ||
|
||
The plugin generates these targets with bare minimum (no extra) options configuration. Any options you need for your Vite app, you can add in your project's `vite.config.ts`. | ||
|
||
If you want to add some universal options for all your `build` targets, for example, you can still do so in the [`targetDefaults`](/recipes/running-tasks/reduce-repetitive-configuration#reduce-configuration-with-targetdefaults). | ||
|
||
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/vite/plugin", | ||
"options": { | ||
"buildTargetName": "build-core", | ||
"previewTargetName": "preview", | ||
"serveTargetName": "serve", | ||
"testTargetName": "test", | ||
"serveStaticTargetName": "static-serve", | ||
}, | ||
}, | ||
... | ||
] | ||
``` | ||
|
||
and this will create `build-core`, `preview`, `test` and `serve` targets in your project graph. You can then call `nx build-core my-app` for all your projects that have a `vite.config.ts|js` file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { cleanupProject, newProject, runCLI, uniq } from '@nx/e2e/utils'; | ||
|
||
const myApp = uniq('my-app'); | ||
|
||
describe('@nx/vite/plugin', () => { | ||
let proj: string; | ||
let originalEnv: string; | ||
|
||
beforeAll(() => { | ||
originalEnv = process.env.NX_PCV3; | ||
process.env.NX_PCV3 = 'true'; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env.NODE_ENV = originalEnv; | ||
}); | ||
|
||
describe('build and test React Vite app', () => { | ||
beforeAll(() => { | ||
proj = newProject(); | ||
runCLI( | ||
`generate @nx/react:app ${myApp} --bundler=vite --unitTestRunner=vitest` | ||
); | ||
}); | ||
|
||
afterAll(() => cleanupProject()); | ||
|
||
it('should build application', () => { | ||
const result = runCLI(`build ${myApp}`); | ||
expect(result).toContain('Successfully ran target build'); | ||
}, 200_000); | ||
|
||
it('should test application', () => { | ||
const result = runCLI(`test ${myApp}`); | ||
expect(result).toContain('Successfully ran target test'); | ||
}, 200_000); | ||
}); | ||
|
||
describe('build and test Vue app', () => { | ||
beforeAll(() => { | ||
proj = newProject(); | ||
runCLI(`generate @nx/vue:app ${myApp} --unitTestRunner=vitest`); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanupProject(); | ||
}); | ||
|
||
it('should build application', () => { | ||
const result = runCLI(`build ${myApp}`); | ||
expect(result).toContain('Successfully ran target build'); | ||
}, 200_000); | ||
|
||
it('should test application', () => { | ||
const result = runCLI(`test ${myApp}`); | ||
expect(result).toContain('Successfully ran target test'); | ||
}, 200_000); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { | ||
createNodes, | ||
VitePluginOptions, | ||
createDependencies, | ||
} from './src/plugins/plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.