@nestbridge/webpack 2.0.2 → 2.0.4
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 +94 -0
- package/build/nestbridge.webpack.d.ts +19 -0
- package/build/nestbridge.webpack.js +1116 -0
- package/build/nestbridge.webpack.js.map +1 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @nestbridge/webpack
|
|
2
|
+
|
|
3
|
+
[](https://github.com/MDReal32/nestbridge/actions/workflows/release.yml)
|
|
4
|
+
[](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/@nestbridge/webpack)
|
|
6
|
+
|
|
7
|
+
A webpack plugin that lets frontend code import a NestJS controller or
|
|
8
|
+
GraphQL resolver directly — keeping full TypeScript autocomplete against its
|
|
9
|
+
real method signatures, while the browser only ever receives a generated
|
|
10
|
+
`fetch()` call or GraphQL request. See the [repository README](../../README.md)
|
|
11
|
+
for the full explanation of how NestJS is kept out of the client bundle.
|
|
12
|
+
|
|
13
|
+
This plugin is a thin `webpack` binding around the bundler-agnostic
|
|
14
|
+
[`@nestbridge/unplugin`](../unplugin) engine — the same one that
|
|
15
|
+
[`@nestbridge/vite`](../vite) wraps for Vite — so discovery, code generation,
|
|
16
|
+
and declaration writing behave identically across both bundlers.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
yarn add -D @nestbridge/webpack
|
|
22
|
+
yarn add @nestbridge/runtime
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
// webpack.config.js
|
|
29
|
+
const { resolve } = require('node:path');
|
|
30
|
+
const { nestBridge } = require('@nestbridge/webpack');
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
resolve: {
|
|
34
|
+
alias: {
|
|
35
|
+
'@server': resolve(__dirname, '../server/src'),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
module: {
|
|
39
|
+
rules: [{ test: /\.tsx?$/, loader: 'esbuild-loader' }],
|
|
40
|
+
},
|
|
41
|
+
plugins: [
|
|
42
|
+
nestBridge({
|
|
43
|
+
controllers: '../server/src/**/*.controller.ts',
|
|
44
|
+
resolvers: '../server/src/**/*.resolver.ts',
|
|
45
|
+
baseURL: '/api',
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`resolvers` is optional — omit it if your app has no GraphQL resolvers. The
|
|
52
|
+
`resolve.alias` entry lets webpack find the real controller and resolver
|
|
53
|
+
files so the plugin can intercept them. A matching `paths` entry in
|
|
54
|
+
`tsconfig.json` lets TypeScript find the *generated* declarations instead:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"compilerOptions": {
|
|
59
|
+
"baseUrl": ".",
|
|
60
|
+
"paths": {
|
|
61
|
+
"@server/*": ["./.nestbridge/server/src/*"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Add `.nestbridge/` (or your configured `outputDir`) to `.gitignore` — it's
|
|
68
|
+
regenerated on every build and on every dev-server start.
|
|
69
|
+
|
|
70
|
+
Unlike Vite, webpack has no build-time hook the plugin can use to discover
|
|
71
|
+
the project root automatically, so it defaults to `process.cwd()`. Pass an
|
|
72
|
+
explicit `root` if `webpack.config.js` runs from somewhere other than the
|
|
73
|
+
directory your `controllers`/`resolvers` globs are relative to.
|
|
74
|
+
|
|
75
|
+
## `NestBridgeOptions`
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
interface NestBridgeOptions {
|
|
79
|
+
controllers: string | string[]; // glob(s), resolved relative to `root`
|
|
80
|
+
resolvers?: string | string[]; // glob(s) for GraphQL resolvers; defaults to none
|
|
81
|
+
baseURL?: string; // informational; call configureNestBridge for the runtime effect
|
|
82
|
+
debug?: boolean; // logs discovery/analysis/HMR activity
|
|
83
|
+
outputDir?: string; // defaults to ".nestbridge"
|
|
84
|
+
root?: string; // defaults to process.cwd()
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Don't forget to call `configureNestBridge` from `@nestbridge/runtime` — this
|
|
89
|
+
option only affects generated path text, not the runtime `fetch()`/GraphQL
|
|
90
|
+
config (`baseURL`/`graphqlEndpoint`).
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WebpackPluginInstance } from "webpack";
|
|
2
|
+
//#region ../unplugin/src/options/nestbridge-options.d.ts
|
|
3
|
+
interface NestBridgeOptions {
|
|
4
|
+
controllers: string | string[];
|
|
5
|
+
resolvers?: string | string[];
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
outputDir?: string;
|
|
9
|
+
root?: string;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/version.d.ts
|
|
13
|
+
export declare const VERSION: string;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/main.d.ts
|
|
16
|
+
export declare const nestBridge: (options: NestBridgeOptions) => WebpackPluginInstance;
|
|
17
|
+
//#endregion
|
|
18
|
+
export type { NestBridgeOptions };
|
|
19
|
+
//# sourceMappingURL=nestbridge.webpack.d.ts.map
|