@pitlane/dev 0.3.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @pitlane/dev
2
2
 
3
+ ## 0.4.0
4
+
5
+ SPA mode.
6
+
7
+ - `remix({ server: false })` targets client-rendered apps. No server
8
+ environment is configured, nothing builds to `dist/ssr`, and `vite build`
9
+ emits a static site from `index.html`. What remains is the part a SPA still
10
+ wants: component HMR through the `remix/ui-hmr` browser transform, including
11
+ the arrow-form normalization, so edits hot-swap in place and keep live
12
+ component state. Every `server*` option goes with it, and `clientEntry` too,
13
+ and `<HMR />` from `pitlane:dev` resolves to the inert component — there is
14
+ no server data to revalidate.
15
+ - The option is named for what it removes. React Router spells the same switch
16
+ `ssr: false`, which reads like it only turns off server rendering; it does
17
+ not, in either plugin. An app that wants browser-rendered UI in front of
18
+ routes that still run per request keeps `server: true` and writes a server
19
+ entry that answers data and a shell.
20
+ - SPA mode works under Vite's experimental bundled dev mode
21
+ (`experimental.bundledDev` / `vite dev --experimentalBundle`), component
22
+ hot-swap included. Server-rendered apps do not: bundled dev serves only
23
+ bundle entrypoints, so the client module URLs an SSR render writes into its
24
+ HTML have nothing behind them. That is upstream's Phase 4 (server
25
+ environments), still a prototype.
26
+
3
27
  ## 0.3.0
4
28
 
5
29
  Dev-time hot module replacement.
package/README.md CHANGED
@@ -114,6 +114,7 @@ Leave it unguarded: in a production build the specifier resolves to a component
114
114
 
115
115
  ```ts
116
116
  remix({
117
+ server: true, // default — false selects SPA mode
117
118
  clientEntry: "app/entry.browser", // default — false disables the client build
118
119
  serverEntry: "app/entry.server", // default
119
120
  serverEnvironments: ["ssr"], // default
@@ -123,11 +124,57 @@ remix({
123
124
 
124
125
  | Option | Type | Default | Purpose |
125
126
  | -------------------- | ----------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
127
+ | `server` | `boolean` | `true` | Whether the app has a server. Pass `false` for [SPA mode](#spa-mode), which ignores every option below. |
126
128
  | `clientEntry` | `string \| false` | `"app/entry.browser"` | Client entry module. Pass `false` for fully server-rendered apps with no hydration. |
127
129
  | `serverEntry` | `string` | `"app/entry.server"` | Server entry module, built as `dist/ssr/index.js`. |
128
130
  | `serverEnvironments` | `string[]` | `["ssr"]` | Environment names the `clientEntry()` transform treats as "server". |
129
131
  | `serverHandler` | `boolean` | `true` | Serve dev requests through your server entry. Set `false` when `@cloudflare/vite-plugin`, `@netlify/vite-plugin`, or `nitro/vite` owns dev-time request handling. |
130
132
 
133
+ ## SPA mode
134
+
135
+ Some apps have no server — a static host, a router that never touches one.
136
+ `remix({ server: false })` targets those. React Router spells the same switch
137
+ `ssr: false`:
138
+
139
+ ```ts
140
+ // vite.config.ts
141
+ import { remix } from "@pitlane/dev";
142
+ import { defineConfig } from "vite";
143
+
144
+ export default defineConfig({
145
+ plugins: [remix({ server: false })],
146
+ });
147
+ ```
148
+
149
+ There is no server environment, nothing is built to `dist/ssr`, and
150
+ `vite build` emits a static site from your `index.html`. The plugin's one
151
+ remaining job is the one a SPA still wants: component HMR. Editing a component
152
+ swaps it in place and keeps live state, arrow forms included.
153
+
154
+ Every `server*` option goes with it, and `clientEntry` too — the browser entry
155
+ is whatever `index.html` loads. `<HMR />` from `pitlane:dev` resolves to the
156
+ inert component, because there is no server data to revalidate.
157
+
158
+ Deploying means pointing every unknown URL at `index.html` so the client router
159
+ can resolve it; on GitHub Pages that is a copy of `index.html` at `404.html`,
160
+ on Netlify a `/* /index.html 200` redirect.
161
+
162
+ The option removes the server, not the server rendering, which is what React
163
+ Router's `ssr: false` does too. For a browser-rendered UI in front of routes
164
+ that still run per request, stay in the default mode and let the server entry
165
+ answer JSON on its data routes and one `remix/ui` shell on its document
166
+ routes: nothing here asks it to render app UI. [Client rendering with a
167
+ server](https://pitlane.tools/guides/spa#client-rendering-with-a-server) shows
168
+ the shape.
169
+
170
+ SPA mode also works under Vite's experimental bundled dev mode
171
+ (`experimental.bundledDev`, or `vite dev --experimentalBundle`), component
172
+ hot-swap included. Server-rendered apps do not yet: bundled dev serves only
173
+ bundle entrypoints, so the client module URLs an SSR render writes into its
174
+ HTML resolve to nothing. That is upstream's
175
+ [Phase 4](https://github.com/vitejs/vite/discussions/22746) — server
176
+ environments — still a prototype.
177
+
131
178
  ## The server entry contract
132
179
 
133
180
  The server entry **default-exports a fetch handler** — an object exposing `fetch(request: Request): Response | Promise<Response>`. A `createRouter()` router already is one:
package/dist/index.d.mts CHANGED
@@ -9,6 +9,21 @@ interface RemixPluginOptions {
9
9
  * @default "app/entry.browser"
10
10
  */
11
11
  clientEntry?: string | false;
12
+ /**
13
+ * Whether the app has a server at all. Pass `false` for SPA mode: no
14
+ * server environment is configured, nothing is built to `dist/ssr`, and
15
+ * `vite build` emits a static site from `index.html`.
16
+ *
17
+ * This is about the server, not about server rendering. With `false`
18
+ * every `server*` option below goes with it, because there is no server
19
+ * for them to describe, and `clientEntry` goes too: the browser entry is
20
+ * whatever `index.html` loads. An app that wants its UI rendered in the
21
+ * browser while its routes still answer per request keeps `true` and
22
+ * writes a server entry that serves data and a shell.
23
+ *
24
+ * @default true
25
+ */
26
+ server?: boolean;
12
27
  /**
13
28
  * Server entry module, built as `dist/ssr/index.js`. Must default-export
14
29
  * a fetch handler: an object exposing
@@ -31,6 +46,8 @@ interface RemixPluginOptions {
31
46
  * Set to `false` when another plugin owns dev-time request handling —
32
47
  * e.g. `@cloudflare/vite-plugin`, `@netlify/vite-plugin`, or `nitro/vite`.
33
48
  *
49
+ * Ignored when `server` is `false`, which has no fetch handler.
50
+ *
34
51
  * @default true
35
52
  */
36
53
  serverHandler?: boolean;
package/dist/index.mjs CHANGED
@@ -649,7 +649,8 @@ function findClientEntryCalls(program) {
649
649
  * Deno.
650
650
  */
651
651
  function remix(options = {}) {
652
- let { clientEntry = "app/entry.browser", serverEntry = "app/entry.server", serverEnvironments = ["ssr"], serverHandler = true } = options;
652
+ let { clientEntry = "app/entry.browser", server = true, serverEntry = "app/entry.server", serverEnvironments = ["ssr"], serverHandler = true } = options;
653
+ if (!server) return spa();
653
654
  let serverEnvironmentSet = new Set(serverEnvironments);
654
655
  return [
655
656
  fullstack({
@@ -672,6 +673,24 @@ function remix(options = {}) {
672
673
  ];
673
674
  }
674
675
  /**
676
+ * SPA mode: the subset of `remix()` that applies when there is no server.
677
+ * Vite already serves `index.html` and builds it to a static site, so the only
678
+ * thing left to wire is component hot module replacement — which a
679
+ * client-rendered app wants just as much as a server-rendered one.
680
+ *
681
+ * Everything server-shaped is absent by construction: no server environment,
682
+ * no `dist/ssr`, no dev fetch handler, and no server-data HMR (there is no
683
+ * server data to revalidate, so `<HMR />` resolves to the inert component).
684
+ */
685
+ function spa() {
686
+ let serverEnvironmentSet = /* @__PURE__ */ new Set();
687
+ return [
688
+ componentHmr(serverEnvironmentSet),
689
+ hmrComponent(false),
690
+ clientEntryTransform(serverEnvironmentSet)
691
+ ];
692
+ }
693
+ /**
675
694
  * Suppresses `aborted` errors from client disconnects (e.g. search-as-you-type
676
695
  * or navigating away mid-fetch) that would otherwise trigger Vite's dev error
677
696
  * overlay. The match is deliberately narrow so real failures still propagate.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pitlane/dev",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "remix() — the Remix 3 Vite plugin: build orchestration, clientEntry() hydration transform, dev server with component and server-data HMR, and preview for any Vite or Vite+ project.",
5
5
  "keywords": [
6
6
  "pitlane",