Skip to content

Commit

Permalink
feat(platform): add Vite dev-server/build and Vitest executors (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts authored Oct 24, 2023
1 parent 2e47410 commit ff168ff
Show file tree
Hide file tree
Showing 20 changed files with 426 additions and 13 deletions.
10 changes: 5 additions & 5 deletions apps/docs-app/docs/features/testing/vitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ To add Vitest, install the necessary packages:
<TabItem value="npm">

```shell
npm install @analogjs/vite-plugin-angular @nx/vite jsdom vite-tsconfig-paths --save-dev
npm install @analogjs/vite-plugin-angular @analogjs/platform jsdom vite-tsconfig-paths --save-dev
```

</TabItem>

<TabItem label="Yarn" value="yarn">

```shell
yarn add @analogjs/vite-plugin-angular @nx/vite jsdom vite-tsconfig-paths --dev
yarn add @analogjs/vite-plugin-angular @analogjs/platform jsdom vite-tsconfig-paths --dev
```

</TabItem>

<TabItem value="pnpm">

```shell
pnpm install -w @analogjs/vite-plugin-angular @nx/vite jsdom vite-tsconfig-paths
pnpm install -w @analogjs/vite-plugin-angular @analogjs/platform jsdom vite-tsconfig-paths
```

</TabItem>
Expand Down Expand Up @@ -82,7 +82,7 @@ getTestBed().initTestEnvironment(
);
```

Next, update the `test` target in the `angular.json` to use the `@nx/vite:test` builder:
Next, update the `test` target in the `angular.json` to use the `@analogjs/platform:vitest` builder:

```json
{
Expand All @@ -97,7 +97,7 @@ Next, update the `test` target in the `angular.json` to use the `@nx/vite:test`
"serve": ...,
"extract-i18n": ...,
"test": {
"builder": "@nx/vite:test"
"builder": "@analogjs/platform:vitest"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"@nx/cypress": "17.0.1",
"@nx/eslint-plugin": "17.0.1",
"@nx/jest": "17.0.1",
"@nx/js": "17.0.1",
"@nx/plugin": "17.0.1",
"@nx/vite": "17.0.1",
"@nx/web": "17.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-analog/template-angular-v16/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"prefix": "app",
"architect": {
"build": {
"builder": "@nx/vite:build",
"builder": "@analogjs/platform:vite",
"options": {
"configFile": "vite.config.ts",
"main": "src/main.ts",
Expand All @@ -29,7 +29,7 @@
}
},
"serve": {
"builder": "@nx/vite:dev-server",
"builder": "@analogjs/platform:vite-dev-server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "my-app:build",
Expand Down
36 changes: 36 additions & 0 deletions packages/nx-plugin/executors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"builders": {
"vite-dev-server": {
"implementation": "./src/executors/vite-dev-server/compat",
"schema": "./src/executors/vite-dev-server/schema.json",
"description": "Vite dev server."
},
"vite": {
"implementation": "./src/executors/vite/compat",
"schema": "./src/executors/vite/schema.json",
"description": "Build with Vite."
},
"vitest": {
"implementation": "./src/executors/vitest/compat",
"schema": "./src/executors/vitest/schema.json",
"description": "Test with Vitest"
}
},
"executors": {
"vite-dev-server": {
"implementation": "./src/executors/vite-dev-server/vite-dev-server.impl",
"schema": "./src/executors/vite-dev-server/schema.json",
"description": "Vite dev server."
},
"vite": {
"implementation": "./src/executors/vite/vite.impl",
"schema": "./src/executors/vite/schema.json",
"description": "Build with Vite."
},
"vitest": {
"implementation": "./src/executors/vitest/vitest.impl",
"schema": "./src/executors/vitest/schema.json",
"description": "Test with Vitest"
}
}
}
5 changes: 5 additions & 0 deletions packages/nx-plugin/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"input": "./packages/nx-plugin",
"glob": "generators.json",
"output": "."
},
{
"input": "./packages/nx-plugin",
"glob": "executors.json",
"output": "."
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions packages/nx-plugin/src/executors/vite-dev-server/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit';

import viteDevServerExecutor from './vite-dev-server.impl';

export default convertNxExecutor(viteDevServerExecutor);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ViteDevServerExecutorOptions } from '@nx/vite/executors';
101 changes: 101 additions & 0 deletions packages/nx-plugin/src/executors/vite-dev-server/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"version": 2,
"outputCapture": "direct-nodejs",
"title": "Vite Dev Server",
"cli": "nx",
"description": "Starts a dev server using Vite.",
"type": "object",
"presets": [
{
"name": "Default minimum setup",
"keys": ["buildTarget"]
},
{
"name": "Using a Different Port",
"keys": ["buildTarget", "port"]
}
],
"properties": {
"buildTarget": {
"type": "string",
"description": "Target which builds the application. Only used to retrieve the configuration as the dev-server does not build the code.",
"x-priority": "important"
},
"buildLibsFromSource": {
"type": "boolean",
"description": "Read buildable libraries from source instead of building them separately.",
"default": true
},
"proxyConfig": {
"type": "string",
"description": "Path to the proxy configuration file.",
"x-completion-type": "file"
},
"port": {
"type": "number",
"description": "Port to listen on.",
"x-priority": "important"
},
"host": {
"description": "Specify which IP addresses the server should listen on.",
"oneOf": [
{
"type": "boolean"
},
{
"type": "string"
}
]
},
"https": {
"oneOf": [
{
"type": "boolean"
},
{
"type": "object"
}
],
"description": "Serve using HTTPS. https://vitejs.dev/config/server-options.html#server-https"
},
"hmr": {
"description": "Enable hot module replacement. For more options, use the 'hmr' option in the Vite configuration file.",
"type": "boolean"
},
"open": {
"description": "Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname.",
"oneOf": [
{
"type": "boolean"
},
{
"type": "string"
}
]
},
"cors": {
"description": "Configure CORS for the dev server.",
"type": "boolean"
},
"logLevel": {
"type": "string",
"description": "Adjust console output verbosity.",
"enum": ["info", "warn", "error", "silent"]
},
"mode": {
"type": "string",
"description": "Mode to run the server in."
},
"clearScreen": {
"description": "Set to false to prevent Vite from clearing the terminal screen when logging certain messages.",
"type": "boolean"
},
"force": {
"description": "Force the optimizer to ignore the cache and re-bundle",
"type": "boolean"
}
},
"definitions": {},
"required": ["buildTarget"],
"examplesFile": "../../../docs/dev-server-examples.md"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { viteDevServerExecutor } from '@nx/vite/executors';

export default viteDevServerExecutor;
5 changes: 5 additions & 0 deletions packages/nx-plugin/src/executors/vite/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nx/devkit';

import viteBuildExecutor from './vite.impl';

export default convertNxExecutor(viteBuildExecutor);
2 changes: 2 additions & 0 deletions packages/nx-plugin/src/executors/vite/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { FileReplacement } from '@nx/vite/plugins/rollup-replace-files.plugin';
export { ViteBuildExecutorOptions } from '@nx/vite/executors';
Loading

0 comments on commit ff168ff

Please sign in to comment.