@nestbridge/vite 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -0
- package/build/nestbridge.vite.d.ts +1 -0
- package/build/nestbridge.vite.js +733 -32
- package/build/nestbridge.vite.js.map +1 -1
- package/package.json +6 -1
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @nestbridge/vite
|
|
2
|
+
|
|
3
|
+
[](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@nestbridge/vite)
|
|
5
|
+
|
|
6
|
+
A Vite plugin that lets frontend code import a NestJS controller directly —
|
|
7
|
+
keeping full TypeScript autocomplete against its real method signatures,
|
|
8
|
+
while the browser only ever receives a generated `fetch()` call. See the
|
|
9
|
+
[repository README](../../README.md) for the full explanation of how NestJS
|
|
10
|
+
is kept out of the client bundle.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
yarn add -D @nestbridge/vite
|
|
16
|
+
yarn add @nestbridge/runtime
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// vite.config.ts
|
|
23
|
+
import { resolve } from 'node:path';
|
|
24
|
+
import { defineConfig } from 'vite';
|
|
25
|
+
import { nestBridge } from '@nestbridge/vite';
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
resolve: {
|
|
29
|
+
alias: {
|
|
30
|
+
'@server': resolve(__dirname, '../server/src'),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
plugins: [
|
|
34
|
+
nestBridge({
|
|
35
|
+
controllers: '../server/src/**/*.controller.ts',
|
|
36
|
+
baseURL: '/api',
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The `resolve.alias` entry lets the bundler find the real controller files so
|
|
43
|
+
the plugin can intercept them. A matching `paths` entry in `tsconfig.json`
|
|
44
|
+
lets TypeScript find the *generated* declarations instead:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"compilerOptions": {
|
|
49
|
+
"baseUrl": ".",
|
|
50
|
+
"paths": {
|
|
51
|
+
"@server/*": ["./.nestbridge/server/src/*"]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Add `.nestbridge/` (or your configured `outputDir`) to `.gitignore` — it's
|
|
58
|
+
regenerated on every build and on every dev-server start.
|
|
59
|
+
|
|
60
|
+
## `NestBridgeOptions`
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
interface NestBridgeOptions {
|
|
64
|
+
controllers: string | string[]; // glob(s), resolved relative to the Vite root
|
|
65
|
+
baseURL?: string; // informational; call configureNestBridge for the runtime effect
|
|
66
|
+
debug?: boolean; // logs discovery/analysis/HMR activity
|
|
67
|
+
outputDir?: string; // defaults to ".nestbridge"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Don't forget to call `configureNestBridge` from `@nestbridge/runtime` — this
|
|
72
|
+
option only affects generated path text, not the runtime `fetch()` config.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|