Skip to content

Commit adb5e15

Browse files
authored
Merge pull request #3776 from hey-api/feat/vite-plugin-api
feat: expose vite options
2 parents 0673f9d + 664cf85 commit adb5e15

File tree

8 files changed

+62
-12
lines changed

8 files changed

+62
-12
lines changed

.changeset/ten-candles-stick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/vite-plugin": patch
3+
---
4+
5+
**api**: expose `vite` options

.vscode/tasks.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"args": ["turbo", "run", "build", "--filter=@hey-api/openapi-ts"],
99
"group": "build",
1010
"problemMatcher": ["$tsc"],
11-
"presentation": { "reveal": "silent", "close": true }
11+
"presentation": {
12+
"reveal": "silent",
13+
"close": true
14+
}
1215
},
1316
{
1417
"label": "build:openapi-python",
@@ -17,7 +20,10 @@
1720
"args": ["turbo", "run", "build", "--filter=@hey-api/openapi-python"],
1821
"group": "build",
1922
"problemMatcher": ["$tsc"],
20-
"presentation": { "reveal": "silent", "close": true }
23+
"presentation": {
24+
"reveal": "silent",
25+
"close": true
26+
}
2127
}
2228
]
2329
}

docs/openapi-ts/configuration/vite.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Vite Plugin
3-
description: Integrate @hey-api/openapi-ts into your Vite build pipeline with the official Vite plugin.
3+
description: Integrate @hey-api/openapi-ts into your Vite 5, 6, 7, or 8 build pipeline with the official Vite plugin.
44
---
55

66
# Vite
@@ -15,7 +15,7 @@ The Vite plugin integrates `@hey-api/openapi-ts` into the Vite build pipeline, r
1515

1616
- runs automatically as part of your Vite build
1717
- reads your existing [configuration](/openapi-ts/get-started) (or accepts inline config)
18-
- works with any Vite-based project
18+
- supports Vite 5, 6, 7, and 8
1919

2020
## Installation
2121

@@ -62,7 +62,7 @@ The plugin will automatically pick up your [configuration](/openapi-ts/configura
6262

6363
::: code-group
6464

65-
```ts [vite.config.ts]
65+
```js [vite.config.ts]
6666
import { heyApiPlugin } from '@hey-api/vite-plugin';
6767
import { defineConfig } from 'vite';
6868

@@ -80,5 +80,32 @@ export default defineConfig({
8080

8181
:::
8282

83+
## Vite Options
84+
85+
You can pass Vite Plugin API options using the `vite` option. For example, to run the plugin only during development:
86+
87+
::: code-group
88+
89+
```js [vite.config.ts]
90+
import { heyApiPlugin } from '@hey-api/vite-plugin';
91+
import { defineConfig } from 'vite';
92+
93+
export default defineConfig({
94+
plugins: [
95+
heyApiPlugin({
96+
config: {
97+
input: 'hey-api/backend',
98+
output: 'src/client',
99+
},
100+
vite: {
101+
apply: 'serve',
102+
},
103+
}),
104+
],
105+
});
106+
```
107+
108+
:::
109+
83110
<!--@include: ../../partials/examples.md-->
84111
<!--@include: ../../partials/sponsors.md-->

docs/openapi-ts/get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ createClient({
107107

108108
### Vite
109109

110-
If you're using [Vite](https://vite.dev), you can integrate `@hey-api/openapi-ts` directly into your build pipeline with `@hey-api/vite-plugin`. Install it alongside the main package:
110+
If you're using [Vite](https://vite.dev) 5, 6, 7, or 8, you can integrate `@hey-api/openapi-ts` directly into your build pipeline with `@hey-api/vite-plugin`. Install it alongside the main package:
111111

112112
::: code-group
113113

packages/vite-plugin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Part of the Hey API ecosystem.
3232

3333
- runs automatically as part of your Vite build
3434
- reads your existing configuration (or accepts inline config)
35-
- works with any Vite-based project
35+
- supports Vite 5, 6, 7, and 8
3636
- [sync with Hey API Registry](https://heyapi.dev/openapi-ts/integrations) for spec management
3737

3838
<!-- template-contributing-start -->

packages/vite-plugin/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"vite": "8.0.8"
5656
},
5757
"peerDependencies": {
58-
"@hey-api/openapi-ts": "<2"
58+
"@hey-api/openapi-ts": "<2",
59+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
5960
}
6061
}

packages/vite-plugin/src/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import { createClient } from '@hey-api/openapi-ts';
2+
import type { Plugin } from 'vite';
23

3-
export function heyApiPlugin(options?: {
4+
export interface HeyApiPluginOptions {
45
/**
56
* `@hey-api/openapi-ts` configuration options.
67
*/
78
config?: Parameters<typeof createClient>[0];
8-
}) {
9+
/**
10+
* Vite plugin API options.
11+
*/
12+
vite?: Omit<Plugin, 'configResolved' | 'name'>;
13+
}
14+
15+
export function heyApiPlugin(options?: HeyApiPluginOptions): Plugin {
916
return {
10-
configResolved: async () => {
17+
enforce: 'pre',
18+
...options?.vite,
19+
async configResolved() {
1120
await createClient(options?.config);
1221
},
13-
enforce: 'pre',
1422
name: 'hey-api-plugin',
1523
};
1624
}

packages/vite-plugin/tsdown.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export default defineConfig({
55
ignoreRules: ['cjs-resolves-to-esm'],
66
profile: 'esm-only',
77
},
8+
deps: {
9+
neverBundle: ['vite'],
10+
},
811
publint: true,
912
sourcemap: true,
1013
});

0 commit comments

Comments
 (0)