phantom-build 0.4.0 → 0.4.2
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/LICENSE +21 -0
- package/README.md +45 -3
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Randy Wilson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install phantom-build
|
|
|
10
10
|
|
|
11
11
|
## What It Does
|
|
12
12
|
|
|
13
|
-
Phantom runs at build time (Vite or
|
|
13
|
+
Phantom runs at build time (Vite, Webpack, or Rspack) and does two things:
|
|
14
14
|
|
|
15
15
|
**1. Handler extraction** — Event handlers that touch browser APIs (`window`, `document`, `localStorage`, etc.) are extracted into separate chunks and loaded on-demand when the user first interacts.
|
|
16
16
|
|
|
@@ -62,6 +62,24 @@ export default {
|
|
|
62
62
|
};
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
### Rsbuild
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// rsbuild.config.ts
|
|
69
|
+
import { defineConfig } from '@rsbuild/core';
|
|
70
|
+
import { pluginReact } from '@rsbuild/plugin-react';
|
|
71
|
+
import phantom from 'phantom-build/rspack';
|
|
72
|
+
|
|
73
|
+
export default defineConfig({
|
|
74
|
+
plugins: [pluginReact()],
|
|
75
|
+
tools: {
|
|
76
|
+
rspack: {
|
|
77
|
+
plugins: [phantom()],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
65
83
|
That's it. Run your build and Phantom handles the rest.
|
|
66
84
|
|
|
67
85
|
## How It Works
|
|
@@ -94,7 +112,7 @@ export function InteractiveComponent() {
|
|
|
94
112
|
Phantom produces:
|
|
95
113
|
|
|
96
114
|
- **Client code** — handlers are replaced with lightweight stubs that lazy-load the real logic on first click
|
|
97
|
-
- **Chunk modules** —
|
|
115
|
+
- **Chunk modules** — handlers from the same source file are grouped into a single chunk module, loaded on demand
|
|
98
116
|
|
|
99
117
|
The stub calls `e.preventDefault()` and `e.stopPropagation()` synchronously (before the import), so critical event behavior is never delayed. The heavy logic (`window.location.href`, `localStorage`, etc.) loads asynchronously.
|
|
100
118
|
|
|
@@ -209,6 +227,12 @@ phantom({
|
|
|
209
227
|
|
|
210
228
|
// SSR mode: skip all transforms for server builds. Default: false
|
|
211
229
|
ssr: false,
|
|
230
|
+
|
|
231
|
+
// Automatically detect SSR boundaries for components.
|
|
232
|
+
// 'auto': Analyze and add results to manifest (report-only)
|
|
233
|
+
// 'annotate': Prepend "use client" to ClientOnly modules
|
|
234
|
+
// false: Disabled (default)
|
|
235
|
+
ssrBoundaries: false,
|
|
212
236
|
})
|
|
213
237
|
```
|
|
214
238
|
|
|
@@ -246,6 +270,24 @@ export default {
|
|
|
246
270
|
};
|
|
247
271
|
```
|
|
248
272
|
|
|
273
|
+
#### Rsbuild
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
// rsbuild.config.server.ts
|
|
277
|
+
import { defineConfig } from '@rsbuild/core';
|
|
278
|
+
import { pluginReact } from '@rsbuild/plugin-react';
|
|
279
|
+
import phantom from 'phantom-build/rspack';
|
|
280
|
+
|
|
281
|
+
export default defineConfig({
|
|
282
|
+
plugins: [pluginReact()],
|
|
283
|
+
tools: {
|
|
284
|
+
rspack: {
|
|
285
|
+
plugins: [phantom({ ssr: true })],
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
249
291
|
#### Typical Setup
|
|
250
292
|
|
|
251
293
|
Most custom SSR setups (e.g., .NET + React, Express + React) use two bundler configs:
|
|
@@ -474,7 +516,7 @@ node benchmarks/lighthouse-compare.mjs --runs=5
|
|
|
474
516
|
|
|
475
517
|
- Node.js >= 18
|
|
476
518
|
- React 16.6+ (for `React.lazy` and `Suspense`)
|
|
477
|
-
- Vite or
|
|
519
|
+
- Vite, Webpack, or Rspack (Rsbuild)
|
|
478
520
|
- For SSR: any custom server setup (Express, .NET, etc.) — not framework-specific
|
|
479
521
|
|
|
480
522
|
## License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phantom-build",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Automatic code-splitting for React — extracts event handlers into lazy-loaded chunks and wraps below-fold components in React.lazy + Suspense at build time",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|