@cpp.js/plugin-webpack 2.0.0-beta.15 → 2.0.0-beta.21
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/AGENTS.md +89 -0
- package/LICENSE +1 -1
- package/package.json +2 -2
package/AGENTS.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# AGENTS.md — @cpp.js/plugin-webpack
|
|
2
|
+
|
|
3
|
+
> Webpack **and Rspack** integration plugin. Same package serves both — Rspack reuses the Webpack plugin contract.
|
|
4
|
+
|
|
5
|
+
## What lives here
|
|
6
|
+
|
|
7
|
+
- `index.js` — exports `class CppjsWebpackPlugin`. Single class, no separate kernel.
|
|
8
|
+
- Sibling package `@cpp.js/plugin-webpack-loader` ships the loader for `.h` files; `getRule()` references it by name.
|
|
9
|
+
|
|
10
|
+
## Class API surface
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
new CppjsWebpackPlugin()
|
|
14
|
+
↓
|
|
15
|
+
.apply(compiler) ← webpack standard plugin hook
|
|
16
|
+
.getRule() ← module.rules entry for .h
|
|
17
|
+
.getDevServerConfig() ← devServer block w/ COOP+COEP + middleware
|
|
18
|
+
.getLoaderOptions() ← escape hatch: cpp.js state passed to other rules
|
|
19
|
+
.setDevServerMiddleware(...) ← internal, called by getDevServerConfig
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
User config consumes all four; see `docs/playbooks/integration/webpack-rspack.md` for the canonical wiring.
|
|
23
|
+
|
|
24
|
+
## Hooks the plugin registers
|
|
25
|
+
|
|
26
|
+
| webpack hook | What it does |
|
|
27
|
+
|--------------|--------------|
|
|
28
|
+
| `compiler.hooks.done` | After every compilation: re-run `createLib + createXCFramework + buildWasm` (mtime-aware via `isSourceNewer`) |
|
|
29
|
+
| `compiler.hooks.afterCompile` | Adds `state.config.paths.native` to `compilation.contextDependencies` so webpack watch picks up `.cpp`/`.h` edits |
|
|
30
|
+
|
|
31
|
+
## DevServer middleware
|
|
32
|
+
|
|
33
|
+
`getDevServerConfig()` returns:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
{
|
|
37
|
+
watchFiles: state.config.paths.native,
|
|
38
|
+
hot: true,
|
|
39
|
+
liveReload: true,
|
|
40
|
+
headers: {
|
|
41
|
+
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
42
|
+
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
43
|
+
},
|
|
44
|
+
setupMiddlewares: (middlewares, devServer) => { ... }
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The middleware adds `/cpp.js` and `/cpp.wasm` routes that pipe the freshly built artifacts. Both routes also re-emit COOP/COEP per-response (belt-and-suspenders for caching layers that strip top-level headers).
|
|
49
|
+
|
|
50
|
+
## Rspack compatibility
|
|
51
|
+
|
|
52
|
+
Rspack copies webpack's plugin / loader shape. The plugin works without modification. The Rspack-specific wrinkle: `getRule()` returns a plain object that Rspack's TypeScript-strict config types may complain about — cast to `RspackOptions['module']['rules'][number]` if needed.
|
|
53
|
+
|
|
54
|
+
## Common pitfalls
|
|
55
|
+
|
|
56
|
+
- **Forgetting `getRule()` while passing the plugin instance.** The `.h` loader rule and the plugin instance are independent registrations; both are required.
|
|
57
|
+
- **Wrapping the plugin's `getDevServerConfig()` and dropping `headers`.** Always spread: `{ ...cppDev, ...custom, headers: { ...cppDev.headers, ...custom.headers } }`.
|
|
58
|
+
- **Trying to inject `getRule()` into `plugins:` array** instead of `module.rules:`. They are distinct.
|
|
59
|
+
- **Babel/SWC running on `.h` first.** Loader chain order matters; `getRule()` test is `/\.h$/` so other rules with broader tests can swallow it. Make sure no rule for `/\.[jt]sx?$/` accidentally matches `.h` (none do by default).
|
|
60
|
+
- **Adding `console.log` for debugging.** Route through `cpp.js` exports — `state.config` carries the logger if you need it. Plugin output should be quiet by default.
|
|
61
|
+
|
|
62
|
+
## Validation
|
|
63
|
+
|
|
64
|
+
Strict gate:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pnpm run ci:linux:build && pnpm run e2e:dev && pnpm run e2e:prod
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Smoke samples:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pnpm --filter=@cpp.js/sample-web-react-rspack run build
|
|
74
|
+
pnpm --filter=@cpp.js/playground-web-rspack run build
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
If you touch the dev-server middleware, also test:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pnpm --filter=@cpp.js/sample-web-react-rspack exec rspack serve
|
|
81
|
+
# verify in browser: COOP/COEP headers present, /cpp.wasm 200
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Reference
|
|
85
|
+
|
|
86
|
+
- Loader package: `cppjs-plugins/cppjs-plugin-webpack-loader/`
|
|
87
|
+
- Integration recipe: `docs/playbooks/integration/webpack-rspack.md`
|
|
88
|
+
- Next.js variant (no devServer): `docs/playbooks/integration/nextjs.md`
|
|
89
|
+
- Canonical samples: `cppjs-sample-web-react-rspack`, `cppjs-playground-web-rspack`
|
package/LICENSE
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cpp.js/plugin-webpack",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.21",
|
|
4
4
|
"description": "Cpp.js Webpack plugin: A tool for seamless C++ integration with the Webpack bundler.",
|
|
5
5
|
"homepage": "https://github.com/bugra9/cpp.js/tree/main/packages/cppjs-plugin-rollup#readme",
|
|
6
6
|
"repository": "https://github.com/bugra9/cpp.js.git",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"cpp.js": "^2.0.0-beta.
|
|
11
|
+
"cpp.js": "^2.0.0-beta.21"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"cpp.js-plugin",
|