phantom-build 0.4.1 → 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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -3
  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 Webpack) and does two things:
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
 
@@ -112,7 +112,7 @@ export function InteractiveComponent() {
112
112
  Phantom produces:
113
113
 
114
114
  - **Client code** — handlers are replaced with lightweight stubs that lazy-load the real logic on first click
115
- - **Chunk modules** — each handler's logic lives in its own small file, loaded on demand
115
+ - **Chunk modules** — handlers from the same source file are grouped into a single chunk module, loaded on demand
116
116
 
117
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.
118
118
 
@@ -227,6 +227,12 @@ phantom({
227
227
 
228
228
  // SSR mode: skip all transforms for server builds. Default: false
229
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,
230
236
  })
231
237
  ```
232
238
 
@@ -264,6 +270,24 @@ export default {
264
270
  };
265
271
  ```
266
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
+
267
291
  #### Typical Setup
268
292
 
269
293
  Most custom SSR setups (e.g., .NET + React, Express + React) use two bundler configs:
@@ -492,7 +516,7 @@ node benchmarks/lighthouse-compare.mjs --runs=5
492
516
 
493
517
  - Node.js >= 18
494
518
  - React 16.6+ (for `React.lazy` and `Suspense`)
495
- - Vite or Webpack
519
+ - Vite, Webpack, or Rspack (Rsbuild)
496
520
  - For SSR: any custom server setup (Express, .NET, etc.) — not framework-specific
497
521
 
498
522
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phantom-build",
3
- "version": "0.4.1",
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",