vite-plugin-react-server 0.1.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/LICENSE +21 -0
- package/README.md +289 -0
- package/dist/build/createBuildConfig.d.ts +12 -0
- package/dist/build/createBuildConfig.d.ts.map +1 -0
- package/dist/build/createBuildConfig.js +55 -0
- package/dist/build/createBuildConfig.js.map +1 -0
- package/dist/checkFilesExist.d.ts +8 -0
- package/dist/checkFilesExist.d.ts.map +1 -0
- package/dist/checkFilesExist.js +61 -0
- package/dist/checkFilesExist.js.map +1 -0
- package/dist/collect-css-manifest.d.ts +4 -0
- package/dist/collect-css-manifest.d.ts.map +1 -0
- package/dist/collect-css-manifest.js +57 -0
- package/dist/collect-css-manifest.js.map +1 -0
- package/dist/components.d.ts +13 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +13 -0
- package/dist/components.js.map +1 -0
- package/dist/copy-dir.d.ts +4 -0
- package/dist/copy-dir.d.ts.map +1 -0
- package/dist/getEnv.d.ts +19 -0
- package/dist/getEnv.d.ts.map +1 -0
- package/dist/getEnv.js +76 -0
- package/dist/getEnv.js.map +1 -0
- package/dist/helpers/normalizedRelativePath.d.ts +9 -0
- package/dist/helpers/normalizedRelativePath.d.ts.map +1 -0
- package/dist/helpers/normalizedRelativePath.js +31 -0
- package/dist/helpers/normalizedRelativePath.js.map +1 -0
- package/dist/helpers/tryManifest.d.ts +8 -0
- package/dist/helpers/tryManifest.d.ts.map +1 -0
- package/dist/html/createPageLoader.d.ts +26 -0
- package/dist/html/createPageLoader.d.ts.map +1 -0
- package/dist/html/createPageLoader.js +70 -0
- package/dist/html/createPageLoader.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +6 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/module-graph.d.ts +10 -0
- package/dist/module-graph.d.ts.map +1 -0
- package/dist/options.d.ts +86 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +251 -0
- package/dist/options.js.map +1 -0
- package/dist/plugin.d.ts +8 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +31 -0
- package/dist/plugin.js.map +1 -0
- package/dist/react-client/plugin.d.ts +4 -0
- package/dist/react-client/plugin.d.ts.map +1 -0
- package/dist/react-client/plugin.js +28 -0
- package/dist/react-client/plugin.js.map +1 -0
- package/dist/react-server/createDevMiddleware.d.ts +8 -0
- package/dist/react-server/createDevMiddleware.d.ts.map +1 -0
- package/dist/react-server/createDevServer.d.ts +4 -0
- package/dist/react-server/createDevServer.d.ts.map +1 -0
- package/dist/react-server/createHandler.d.ts +23 -0
- package/dist/react-server/createHandler.d.ts.map +1 -0
- package/dist/react-server/createHandler.js +110 -0
- package/dist/react-server/createHandler.js.map +1 -0
- package/dist/react-server/createReactNodeStreamer.d.ts +10 -0
- package/dist/react-server/createReactNodeStreamer.d.ts.map +1 -0
- package/dist/react-server/createRscStream.d.ts +4 -0
- package/dist/react-server/createRscStream.d.ts.map +1 -0
- package/dist/react-server/createRscStream.js +47 -0
- package/dist/react-server/createRscStream.js.map +1 -0
- package/dist/react-server/createSsrHandler.d.ts +4 -0
- package/dist/react-server/createSsrHandler.d.ts.map +1 -0
- package/dist/react-server/plugin.d.ts +8 -0
- package/dist/react-server/plugin.d.ts.map +1 -0
- package/dist/react-server/plugin.js +298 -0
- package/dist/react-server/plugin.js.map +1 -0
- package/dist/resolvePage.d.ts +19 -0
- package/dist/resolvePage.d.ts.map +1 -0
- package/dist/resolvePage.js +44 -0
- package/dist/resolvePage.js.map +1 -0
- package/dist/resolveProps.d.ts +19 -0
- package/dist/resolveProps.d.ts.map +1 -0
- package/dist/resolveProps.js +90 -0
- package/dist/resolveProps.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/transformer/index.d.ts +28 -0
- package/dist/transformer/index.d.ts.map +1 -0
- package/dist/transformer/index.js +54 -0
- package/dist/transformer/index.js.map +1 -0
- package/dist/transformer/preserveDirectives.d.ts +4 -0
- package/dist/transformer/preserveDirectives.d.ts.map +1 -0
- package/dist/transformer/preserveDirectives.js +72 -0
- package/dist/transformer/preserveDirectives.js.map +1 -0
- package/dist/transformer/preserver.d.ts +2 -0
- package/dist/transformer/preserver.d.ts.map +1 -0
- package/dist/transformer/transformer.d.ts +30 -0
- package/dist/transformer/transformer.d.ts.map +1 -0
- package/dist/transformer/transformer.js +80 -0
- package/dist/transformer/transformer.js.map +1 -0
- package/dist/transformer/types.d.ts +15 -0
- package/dist/transformer/types.d.ts.map +1 -0
- package/dist/types.d.ts +197 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/worker/createHtmlStream.d.ts +7 -0
- package/dist/worker/createHtmlStream.d.ts.map +1 -0
- package/dist/worker/createWorker.d.ts +3 -0
- package/dist/worker/createWorker.d.ts.map +1 -0
- package/dist/worker/createWorker.js +33 -0
- package/dist/worker/createWorker.js.map +1 -0
- package/dist/worker/loader.d.ts +15 -0
- package/dist/worker/loader.d.ts.map +1 -0
- package/dist/worker/renderPages.d.ts +18 -0
- package/dist/worker/renderPages.d.ts.map +1 -0
- package/dist/worker/renderPages.js +99 -0
- package/dist/worker/renderPages.js.map +1 -0
- package/dist/worker/types.d.ts +31 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/worker.d.ts +7 -0
- package/dist/worker/worker.d.ts.map +1 -0
- package/package.json +116 -0
- package/src/build/createBuildConfig.ts +74 -0
- package/src/checkFilesExist.ts +67 -0
- package/src/collect-css-manifest.ts +76 -0
- package/src/components.tsx +14 -0
- package/src/copy-dir.ts +27 -0
- package/src/getEnv.ts +135 -0
- package/src/helpers/normalizedRelativePath.ts +59 -0
- package/src/helpers/tryManifest.ts +23 -0
- package/src/html/createPageLoader.ts +99 -0
- package/src/index.ts +4 -0
- package/src/manifest.ts +24 -0
- package/src/module-graph.ts +48 -0
- package/src/options.ts +351 -0
- package/src/plugin.ts +31 -0
- package/src/react-client/plugin.ts +34 -0
- package/src/react-server/createDevMiddleware.ts +75 -0
- package/src/react-server/createDevServer.ts +10 -0
- package/src/react-server/createHandler.ts +144 -0
- package/src/react-server/createReactNodeStreamer.ts +25 -0
- package/src/react-server/createRscStream.ts +52 -0
- package/src/react-server/createSsrHandler.ts +147 -0
- package/src/react-server/plugin.ts +349 -0
- package/src/resolvePage.ts +65 -0
- package/src/resolveProps.ts +122 -0
- package/src/server.tsx +0 -0
- package/src/transformer/README.md +44 -0
- package/src/transformer/index.ts +112 -0
- package/src/transformer/preserveDirectives.ts +100 -0
- package/src/transformer/preserver.ts +47 -0
- package/src/transformer/transformer.ts +123 -0
- package/src/transformer/types.ts +15 -0
- package/src/types.ts +245 -0
- package/src/worker/createHtmlStream.ts +76 -0
- package/src/worker/createWorker.ts +39 -0
- package/src/worker/loader.ts +16 -0
- package/src/worker/renderPages.ts +144 -0
- package/src/worker/types.ts +38 -0
- package/src/worker/worker.tsx +136 -0
- package/tsconfig.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Your Name
|
|
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
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# Vite React Server Components Plugin
|
|
2
|
+
|
|
3
|
+
A Vite plugin that enables React Server Components (RSC) streaming and static building of html pages. Uses experimental dependencies from React, specifically `react-server-dom-esm/server.node`.
|
|
4
|
+
|
|
5
|
+
Temporary patch-package is included in this repository. Example project:
|
|
6
|
+
|
|
7
|
+
the [mmcelebration.com project](https://github.com/nicobrinkkemper/mmc) is using this plugin. The build time for this website of roughly 200 html pages is a couple of seconds - depending on your machine.
|
|
8
|
+
|
|
9
|
+
To achieve a simple workflow, it uses a node worker thread to generate the html for the pages. The reason for this is that we need to keep the client and server build processes separate - yet streaming data towards each other. Running the worker avoids running a server for the build process - and as such doesn't need to run a server to export all the html pages.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 🚀 Super fast static build times
|
|
14
|
+
- 🔄 Use vite to create your personal meta-framework
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install vite-plugin-react-server
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Single vite.config.ts file for server and client build - though you can split it up if you want.
|
|
26
|
+
The import `import { viteReactStreamPlugin } from 'vite-plugin-react-server'` will import the
|
|
27
|
+
right client/server plugin based on the NODE_OPTIONS environment variable.
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// vite.config.ts
|
|
31
|
+
import { defineConfig } from 'vite'
|
|
32
|
+
import { viteReactStreamPlugin } from 'vite-plugin-react-server'
|
|
33
|
+
|
|
34
|
+
// Custom router example
|
|
35
|
+
const createRouter = (fileName: string) => (url: string) => {
|
|
36
|
+
try {
|
|
37
|
+
return new URL(`file://./src/page${url}/${fileName}`).pathname
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return `src/page/404/${fileName}`
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default defineConfig({
|
|
44
|
+
plugins: [
|
|
45
|
+
viteReactStreamPlugin({
|
|
46
|
+
moduleBase: "src",
|
|
47
|
+
Page: createRouter("page.tsx"),
|
|
48
|
+
props: createRouter("props.ts"),
|
|
49
|
+
pageExportName: "Page",
|
|
50
|
+
propsExportName: "props",
|
|
51
|
+
build: {
|
|
52
|
+
client: "dist/client",
|
|
53
|
+
server: "dist/server",
|
|
54
|
+
pages: ()=>["/"]
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
If you want to import the right plugin directly, you can do so like this:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// vite.react.config.ts
|
|
65
|
+
import type { Options } from 'vite-plugin-react-server/server'
|
|
66
|
+
|
|
67
|
+
export const streamPluginOptions: Options = {
|
|
68
|
+
moduleBase: "src",
|
|
69
|
+
Page: `src/page/index.tsx`,
|
|
70
|
+
props: `src/page/index.tsx`,
|
|
71
|
+
pageExportName: "Page",
|
|
72
|
+
propsExportName: "props",
|
|
73
|
+
Html: ({children})=>(<html><body>{children}</body></html>),
|
|
74
|
+
build: {
|
|
75
|
+
client: "dist/client",
|
|
76
|
+
server: "dist/server",
|
|
77
|
+
pages: ()=>["/"]
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// vite.server.config.ts
|
|
84
|
+
import { viteReactStreamPlugin } from 'vite-plugin-react-server/server'
|
|
85
|
+
import { streamPluginOptions } from './vite.react.config.js'
|
|
86
|
+
|
|
87
|
+
export default defineConfig({
|
|
88
|
+
plugins: [viteReactStreamPlugin(streamPluginOptions)]
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
```typescript
|
|
92
|
+
// vite.config.ts
|
|
93
|
+
import { viteReactStreamPlugin } from 'vite-plugin-react-server/client'
|
|
94
|
+
import { streamPluginOptions } from './vite.react.config.js'
|
|
95
|
+
|
|
96
|
+
export default defineConfig({
|
|
97
|
+
plugins: [viteReactStreamPlugin(streamPluginOptions)]
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
Then in the package.json, add the scripts:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
"scripts": {
|
|
104
|
+
"start": "NODE_OPTIONS=--conditions=react-server vite",
|
|
105
|
+
"build": "npm run build:client && npm run build:server",
|
|
106
|
+
"build:client": "vite build",
|
|
107
|
+
"build:server": "NODE_OPTIONS=--conditions=react-server vite build --ssr --config vite.server.config.ts",
|
|
108
|
+
"test:server": "NODE_OPTIONS=--conditions=react-server vitest --config vite.server.config.ts"
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Unfortunately, you can not write jsx in the config file since vite does not support the `.tsx` extension - any other file will be fine and jsx works like you would expect.
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
## Server Components
|
|
116
|
+
|
|
117
|
+
Create server components in your pages directory:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// src/page/pokemon/page.tsx
|
|
121
|
+
export function Page({ pokemon }) {
|
|
122
|
+
return <div>Its a {pokemon.name}!</div>
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Page Props
|
|
127
|
+
|
|
128
|
+
Define props for your pages:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// src/page/pokemon/props.ts
|
|
132
|
+
export const props = async () => {
|
|
133
|
+
const res = await fetch("https://pokeapi.co/api/v2/pokemon-form/399/")
|
|
134
|
+
return res.json()
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Client Entry
|
|
139
|
+
|
|
140
|
+
How to fetch the server component streams, I suggest to make a file like this:
|
|
141
|
+
```typescript
|
|
142
|
+
// src/createReactFetcher.tsx
|
|
143
|
+
import type { ReactNode } from "react";
|
|
144
|
+
import { createFromFetch } from "react-server-dom-esm/client.browser";
|
|
145
|
+
import { callServer } from "./callServer.js";
|
|
146
|
+
|
|
147
|
+
export function createReactFetcher({
|
|
148
|
+
url = window.location.pathname,
|
|
149
|
+
moduleBaseURL = "/src",
|
|
150
|
+
headers = { Accept: "text/x-component" },
|
|
151
|
+
}: {
|
|
152
|
+
url?: string;
|
|
153
|
+
moduleBaseURL?: string;
|
|
154
|
+
headers?: HeadersInit;
|
|
155
|
+
} = {}): Promise<ReactNode> {
|
|
156
|
+
return createFromFetch(
|
|
157
|
+
fetch(url, {
|
|
158
|
+
headers: headers,
|
|
159
|
+
}),
|
|
160
|
+
{
|
|
161
|
+
callServer: callServer,
|
|
162
|
+
moduleBaseURL: new URL(moduleBaseURL, window.origin).href,
|
|
163
|
+
}
|
|
164
|
+
) as Promise<ReactNode>;
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
then use it in your client entry file:
|
|
168
|
+
```typescript
|
|
169
|
+
// src/client.tsx
|
|
170
|
+
const Shell: React.FC<{
|
|
171
|
+
data: React.Usable<unknown>;
|
|
172
|
+
}> = ({ data: initialServerData }) => {
|
|
173
|
+
const [, startTransition] = useTransition();
|
|
174
|
+
const [storeData, setStoreData] =
|
|
175
|
+
useState<React.Usable<unknown>>(initialServerData);
|
|
176
|
+
|
|
177
|
+
const navigate = useCallback((to: string) => {
|
|
178
|
+
startTransition(() => {
|
|
179
|
+
// Create new RSC data stream
|
|
180
|
+
setStoreData(
|
|
181
|
+
createReactFetcher({
|
|
182
|
+
url: to + to.endsWith("/") ? "index.rsc" : "/index.rsc",
|
|
183
|
+
})
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
}, []);
|
|
187
|
+
|
|
188
|
+
// Routing example, useEventListener would just use useEffect and window.addEventListener
|
|
189
|
+
useEventListener("popstate", (e) => {
|
|
190
|
+
if (e instanceof PopStateEvent) {
|
|
191
|
+
if (e.state?.to) {
|
|
192
|
+
return navigate(e.state.to);
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
return navigate(window.location.pathname);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const content = use(storeData);
|
|
200
|
+
|
|
201
|
+
return <ErrorBoundary>{content as ReactNode}</ErrorBoundary>;
|
|
202
|
+
};
|
|
203
|
+
// Initialize the app
|
|
204
|
+
const rootElement = document.getElementById("root");
|
|
205
|
+
if (!rootElement) throw new Error("Root element not found");
|
|
206
|
+
|
|
207
|
+
const intitalData = createReactFetcher({
|
|
208
|
+
url: "/index.rsc",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
createRoot(rootElement).render(<Shell data={intitalData} />);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## HTML Template
|
|
215
|
+
|
|
216
|
+
For development, you can still use the html template - but
|
|
217
|
+
you can provide your own Html function directly in the plugin options.
|
|
218
|
+
```html
|
|
219
|
+
<!DOCTYPE html>
|
|
220
|
+
<html lang="en">
|
|
221
|
+
<head>
|
|
222
|
+
<meta charset="utf-8" />
|
|
223
|
+
<link href="src/index.css" rel="stylesheet" />
|
|
224
|
+
</head>
|
|
225
|
+
<body>
|
|
226
|
+
<div id="root"></div>
|
|
227
|
+
<script type="module" src="/src/client.tsx"></script>
|
|
228
|
+
</body>
|
|
229
|
+
</html>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
## Production html templating
|
|
234
|
+
|
|
235
|
+
The optional Html component can be used to wrap the entire stream. This component is only
|
|
236
|
+
used for production builds - you can not rely on it for development. This is because,
|
|
237
|
+
during development we use vite's native html template and the stream will only contain
|
|
238
|
+
the page content's.
|
|
239
|
+
|
|
240
|
+
The Html component is quite powerful since it gets access to all the page props, the vite client manifest,
|
|
241
|
+
and the children of the stream.
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
import React from "react";
|
|
245
|
+
import type { Manifest } from "vite";
|
|
246
|
+
import { Favicons } from "./layout/Favicons.js";
|
|
247
|
+
import { Head } from "./layout/Head.js";
|
|
248
|
+
|
|
249
|
+
export const Html = ({
|
|
250
|
+
children,
|
|
251
|
+
pageProps,
|
|
252
|
+
manifest,
|
|
253
|
+
}: {
|
|
254
|
+
children: React.ReactNode;
|
|
255
|
+
pageProps: HtmlProps;
|
|
256
|
+
manifest: Manifest;
|
|
257
|
+
}) => {
|
|
258
|
+
if (process.env["NODE_ENV"] === "production") {
|
|
259
|
+
return (
|
|
260
|
+
<html>
|
|
261
|
+
<head>
|
|
262
|
+
<Head title={pageProps.title} />
|
|
263
|
+
<meta name="description" content={pageProps.description} />
|
|
264
|
+
<Favicons favicons={pageProps.favicons} />
|
|
265
|
+
</head>
|
|
266
|
+
<body>
|
|
267
|
+
<div id="root">{children}</div>
|
|
268
|
+
</body>
|
|
269
|
+
</html>
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
return <>{children}</>;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Notes
|
|
278
|
+
|
|
279
|
+
- Requires `NODE_OPTIONS="--conditions=react-server"` for the Vite process
|
|
280
|
+
- CSS files are automatically collected and link tags emitted
|
|
281
|
+
- Components are streamed only when visited
|
|
282
|
+
- Supports both sync and async props, and all kinds of combinations I haven't tried or tested yet!
|
|
283
|
+
|
|
284
|
+
## License
|
|
285
|
+
|
|
286
|
+
MIT
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InlineConfig } from "vite";
|
|
2
|
+
import type { StreamPluginOptions } from "../types.js";
|
|
3
|
+
type CreateBuildConfigOptions = {
|
|
4
|
+
root: string;
|
|
5
|
+
base: string;
|
|
6
|
+
outDir: string;
|
|
7
|
+
entries: string[];
|
|
8
|
+
options?: StreamPluginOptions;
|
|
9
|
+
};
|
|
10
|
+
export declare function createBuildConfig({ root, base, outDir, entries, options, }: CreateBuildConfigOptions): InlineConfig;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=createBuildConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBuildConfig.d.ts","sourceRoot":"","sources":["../../src/build/createBuildConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,KAAK,wBAAwB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAO,EACP,OAAO,GACR,EAAE,wBAAwB,gBAoD1B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { DEFAULT_CONFIG } from "../options.js";
|
|
4
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
function createBuildConfig({
|
|
6
|
+
root,
|
|
7
|
+
base,
|
|
8
|
+
outDir,
|
|
9
|
+
entries,
|
|
10
|
+
options
|
|
11
|
+
}) {
|
|
12
|
+
const entryInputs = Object.fromEntries(
|
|
13
|
+
entries.map((entry) => {
|
|
14
|
+
const relativePath = entry.replace(root + "/", "");
|
|
15
|
+
const key = relativePath.replace(/\.[^/.]+$/, "");
|
|
16
|
+
return [key, entry];
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
const workerPath = options?.workerPath ? resolve(root, options.workerPath) : resolve(__dirname, "..", DEFAULT_CONFIG.WORKER_PATH);
|
|
20
|
+
const loaderPath = options?.loaderPath ? resolve(root, options.loaderPath) : resolve(__dirname, "..", DEFAULT_CONFIG.LOADER_PATH);
|
|
21
|
+
const config = {
|
|
22
|
+
configFile: false,
|
|
23
|
+
root,
|
|
24
|
+
base,
|
|
25
|
+
build: {
|
|
26
|
+
target: "node18",
|
|
27
|
+
ssr: true,
|
|
28
|
+
ssrEmitAssets: false,
|
|
29
|
+
manifest: true,
|
|
30
|
+
ssrManifest: true,
|
|
31
|
+
outDir,
|
|
32
|
+
rollupOptions: {
|
|
33
|
+
input: {
|
|
34
|
+
...entryInputs,
|
|
35
|
+
worker: workerPath,
|
|
36
|
+
loader: loaderPath
|
|
37
|
+
},
|
|
38
|
+
output: {
|
|
39
|
+
format: "esm",
|
|
40
|
+
preserveModules: true,
|
|
41
|
+
hoistTransitiveImports: false,
|
|
42
|
+
esModule: true,
|
|
43
|
+
entryFileNames: "[name].js",
|
|
44
|
+
chunkFileNames: "[name].js",
|
|
45
|
+
assetFileNames: "[name][extname]"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return config;
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
createBuildConfig
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=createBuildConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBuildConfig.js","sources":["../../src/build/createBuildConfig.ts"],"sourcesContent":["import { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { InlineConfig } from \"vite\";\nimport { DEFAULT_CONFIG } from \"../options.js\";\nimport type { StreamPluginOptions } from \"../types.js\";\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\ntype CreateBuildConfigOptions = {\n root: string;\n base: string;\n outDir: string;\n entries: string[];\n options?: StreamPluginOptions;\n};\n\nexport function createBuildConfig({\n root,\n base,\n outDir,\n entries,\n options,\n}: CreateBuildConfigOptions) {\n // Transform entries into proper input format with unique keys\n const entryInputs = Object.fromEntries(\n entries.map((entry) => {\n // Get the path relative to root\n const relativePath = entry.replace(root + \"/\", \"\");\n // Create a unique key based on the full path\n const key = relativePath.replace(/\\.[^/.]+$/, \"\"); // Remove extension\n\n return [key, entry];\n })\n );\n\n const workerPath = options?.workerPath\n ? resolve(root, options.workerPath)\n : resolve(__dirname, \"..\", DEFAULT_CONFIG.WORKER_PATH);\n\n const loaderPath = options?.loaderPath\n ? resolve(root, options.loaderPath)\n : resolve(__dirname, \"..\", DEFAULT_CONFIG.LOADER_PATH);\n\n const config: InlineConfig = {\n configFile: false,\n root,\n base,\n build: {\n target: \"node18\",\n ssr: true,\n ssrEmitAssets: false,\n manifest: true,\n ssrManifest: true,\n outDir,\n rollupOptions: {\n input: {\n ...entryInputs,\n worker: workerPath,\n loader: loaderPath,\n },\n output: {\n format: \"esm\",\n preserveModules: true,\n hoistTransitiveImports: false,\n esModule: true,\n entryFileNames: \"[name].js\",\n chunkFileNames: \"[name].js\",\n assetFileNames: \"[name][extname]\",\n },\n },\n },\n };\n\n return config;\n}\n"],"names":[],"mappings":";;;AAKA,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAUjD,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA6B;AAE3B,QAAM,cAAc,OAAO;AAAA,IACzB,QAAQ,IAAI,CAAC,UAAU;AAErB,YAAM,eAAe,MAAM,QAAQ,OAAO,KAAK,EAAE;AAEjD,YAAM,MAAM,aAAa,QAAQ,aAAa,EAAE;AAEzC,aAAA,CAAC,KAAK,KAAK;AAAA,IACnB,CAAA;AAAA,EACH;AAEA,QAAM,aAAa,SAAS,aACxB,QAAQ,MAAM,QAAQ,UAAU,IAChC,QAAQ,WAAW,MAAM,eAAe,WAAW;AAEvD,QAAM,aAAa,SAAS,aACxB,QAAQ,MAAM,QAAQ,UAAU,IAChC,QAAQ,WAAW,MAAM,eAAe,WAAW;AAEvD,QAAM,SAAuB;AAAA,IAC3B,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,KAAK;AAAA,MACL,eAAe;AAAA,MACf,UAAU;AAAA,MACV,aAAa;AAAA,MACb;AAAA,MACA,eAAe;AAAA,QACb,OAAO;AAAA,UACL,GAAG;AAAA,UACH,QAAQ;AAAA,UACR,QAAQ;AAAA,QACV;AAAA,QACA,QAAQ;AAAA,UACN,QAAQ;AAAA,UACR,iBAAiB;AAAA,UACjB,wBAAwB;AAAA,UACxB,UAAU;AAAA,UACV,gBAAgB;AAAA,UAChB,gBAAgB;AAAA,UAChB,gBAAgB;AAAA,QAAA;AAAA,MAClB;AAAA,IACF;AAAA,EAEJ;AAEO,SAAA;AACT;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StreamPluginOptions } from "./types.js";
|
|
2
|
+
export declare function checkFilesExist(pages: string[], options: Pick<StreamPluginOptions, "Page" | "props">, root: string): Promise<{
|
|
3
|
+
pageMap: Map<string, string>;
|
|
4
|
+
pageSet: Set<string>;
|
|
5
|
+
propsMap: Map<string, string>;
|
|
6
|
+
propsSet: Set<string>;
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=checkFilesExist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkFilesExist.d.ts","sourceRoot":"","sources":["../src/checkFilesExist.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,EACpD,IAAI,EAAE,MAAM;;;;;GA2Db"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
async function checkFilesExist(pages, options, root) {
|
|
4
|
+
const errors = [];
|
|
5
|
+
const pageSet = /* @__PURE__ */ new Set();
|
|
6
|
+
const pageMap = /* @__PURE__ */ new Map();
|
|
7
|
+
if (typeof options.Page === "string") {
|
|
8
|
+
const pagePath = resolve(root, options.Page);
|
|
9
|
+
pageMap.set(options.Page, pagePath);
|
|
10
|
+
if (!pageSet.has(pagePath)) {
|
|
11
|
+
if (!existsSync(pagePath)) {
|
|
12
|
+
errors.push(`Page file not found: ${pagePath}`);
|
|
13
|
+
}
|
|
14
|
+
pageSet.add(pagePath);
|
|
15
|
+
}
|
|
16
|
+
} else if (typeof options.Page === "function" && pages) {
|
|
17
|
+
for (const page of pages) {
|
|
18
|
+
const pagePath = options.Page(resolve(root, page));
|
|
19
|
+
pageMap.set(page, pagePath);
|
|
20
|
+
if (pageSet.has(pagePath)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!existsSync(pagePath)) {
|
|
24
|
+
errors.push(`Page file not found: ${pagePath}`);
|
|
25
|
+
}
|
|
26
|
+
pageSet.add(pagePath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const propsSet = /* @__PURE__ */ new Set();
|
|
30
|
+
const propsMap = /* @__PURE__ */ new Map();
|
|
31
|
+
if (typeof options.props === "string") {
|
|
32
|
+
const propsPath = resolve(root, options.props);
|
|
33
|
+
propsMap.set(options.props, propsPath);
|
|
34
|
+
if (!propsSet.has(propsPath)) {
|
|
35
|
+
if (!existsSync(propsPath)) {
|
|
36
|
+
errors.push(`Props file not found: ${propsPath}`);
|
|
37
|
+
}
|
|
38
|
+
propsSet.add(propsPath);
|
|
39
|
+
}
|
|
40
|
+
} else if (typeof options.props === "function" && pages) {
|
|
41
|
+
for (const page of pages) {
|
|
42
|
+
const propsPath = options.props(resolve(root, page));
|
|
43
|
+
propsMap.set(page, propsPath);
|
|
44
|
+
if (propsSet.has(propsPath)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!existsSync(propsPath)) {
|
|
48
|
+
errors.push(`Props file not found: ${propsPath}`);
|
|
49
|
+
}
|
|
50
|
+
propsSet.add(propsPath);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (errors.length) {
|
|
54
|
+
throw new Error("React Stream Plugin Validation:\n" + errors.join("\n"));
|
|
55
|
+
}
|
|
56
|
+
return { pageMap, pageSet, propsMap, propsSet };
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
checkFilesExist
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=checkFilesExist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkFilesExist.js","sources":["../src/checkFilesExist.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { StreamPluginOptions } from \"./types.js\";\n\nexport async function checkFilesExist(\n pages: string[],\n options: Pick<StreamPluginOptions, \"Page\" | \"props\">,\n root: string\n) {\n const errors: string[] = [];\n const pageSet = new Set<string>();\n const pageMap = new Map<string, string>();\n // Check if files exist when string paths are provided\n if (typeof options.Page === \"string\") {\n const pagePath = resolve(root, options.Page);\n pageMap.set(options.Page, pagePath);\n if (!pageSet.has(pagePath)) {\n if (!existsSync(pagePath)) {\n errors.push(`Page file not found: ${pagePath}`);\n }\n pageSet.add(pagePath);\n }\n } else if (typeof options.Page === \"function\" && pages) {\n for (const page of pages) {\n const pagePath = options.Page(resolve(root, page));\n pageMap.set(page, pagePath);\n if (pageSet.has(pagePath)) {\n continue;\n }\n if (!existsSync(pagePath)) {\n errors.push(`Page file not found: ${pagePath}`);\n }\n pageSet.add(pagePath);\n }\n }\n\n const propsSet = new Set<string>();\n const propsMap = new Map<string, string>();\n if (typeof options.props === \"string\") {\n const propsPath = resolve(root, options.props);\n propsMap.set(options.props, propsPath);\n if (!propsSet.has(propsPath)) {\n if (!existsSync(propsPath)) {\n errors.push(`Props file not found: ${propsPath}`);\n }\n propsSet.add(propsPath);\n }\n } else if (typeof options.props === \"function\" && pages) {\n for (const page of pages) {\n const propsPath = options.props(resolve(root, page));\n propsMap.set(page, propsPath);\n if (propsSet.has(propsPath)) {\n continue;\n }\n if (!existsSync(propsPath)) {\n errors.push(`Props file not found: ${propsPath}`);\n }\n propsSet.add(propsPath);\n }\n }\n\n if (errors.length) {\n throw new Error(\"React Stream Plugin Validation:\\n\" + errors.join(\"\\n\"));\n }\n\n return { pageMap, pageSet, propsMap, propsSet };\n}\n"],"names":[],"mappings":";;AAIsB,eAAA,gBACpB,OACA,SACA,MACA;AACA,QAAM,SAAmB,CAAC;AACpB,QAAA,8BAAc,IAAY;AAC1B,QAAA,8BAAc,IAAoB;AAEpC,MAAA,OAAO,QAAQ,SAAS,UAAU;AACpC,UAAM,WAAW,QAAQ,MAAM,QAAQ,IAAI;AACnC,YAAA,IAAI,QAAQ,MAAM,QAAQ;AAClC,QAAI,CAAC,QAAQ,IAAI,QAAQ,GAAG;AACtB,UAAA,CAAC,WAAW,QAAQ,GAAG;AAClB,eAAA,KAAK,wBAAwB,QAAQ,EAAE;AAAA,MAAA;AAEhD,cAAQ,IAAI,QAAQ;AAAA,IAAA;AAAA,EAEb,WAAA,OAAO,QAAQ,SAAS,cAAc,OAAO;AACtD,eAAW,QAAQ,OAAO;AACxB,YAAM,WAAW,QAAQ,KAAK,QAAQ,MAAM,IAAI,CAAC;AACzC,cAAA,IAAI,MAAM,QAAQ;AACtB,UAAA,QAAQ,IAAI,QAAQ,GAAG;AACzB;AAAA,MAAA;AAEE,UAAA,CAAC,WAAW,QAAQ,GAAG;AAClB,eAAA,KAAK,wBAAwB,QAAQ,EAAE;AAAA,MAAA;AAEhD,cAAQ,IAAI,QAAQ;AAAA,IAAA;AAAA,EACtB;AAGI,QAAA,+BAAe,IAAY;AAC3B,QAAA,+BAAe,IAAoB;AACrC,MAAA,OAAO,QAAQ,UAAU,UAAU;AACrC,UAAM,YAAY,QAAQ,MAAM,QAAQ,KAAK;AACpC,aAAA,IAAI,QAAQ,OAAO,SAAS;AACrC,QAAI,CAAC,SAAS,IAAI,SAAS,GAAG;AACxB,UAAA,CAAC,WAAW,SAAS,GAAG;AACnB,eAAA,KAAK,yBAAyB,SAAS,EAAE;AAAA,MAAA;AAElD,eAAS,IAAI,SAAS;AAAA,IAAA;AAAA,EAEf,WAAA,OAAO,QAAQ,UAAU,cAAc,OAAO;AACvD,eAAW,QAAQ,OAAO;AACxB,YAAM,YAAY,QAAQ,MAAM,QAAQ,MAAM,IAAI,CAAC;AAC1C,eAAA,IAAI,MAAM,SAAS;AACxB,UAAA,SAAS,IAAI,SAAS,GAAG;AAC3B;AAAA,MAAA;AAEE,UAAA,CAAC,WAAW,SAAS,GAAG;AACnB,eAAA,KAAK,yBAAyB,SAAS,EAAE;AAAA,MAAA;AAElD,eAAS,IAAI,SAAS;AAAA,IAAA;AAAA,EACxB;AAGF,MAAI,OAAO,QAAQ;AACjB,UAAM,IAAI,MAAM,sCAAsC,OAAO,KAAK,IAAI,CAAC;AAAA,EAAA;AAGzE,SAAO,EAAE,SAAS,SAAS,UAAU,SAAS;AAChD;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Manifest, ModuleGraph } from "vite";
|
|
2
|
+
export declare function collectModuleGraphCss(moduleGraph: ModuleGraph, pagePath: string): Promise<Map<string, string>>;
|
|
3
|
+
export declare function collectManifestCss(manifest: Manifest, root: string, pagePath: string, onCss?: (path: string) => void): Map<string, string>;
|
|
4
|
+
//# sourceMappingURL=collect-css-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect-css-manifest.d.ts","sourceRoot":"","sources":["../src/collect-css-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAElD,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,MAAM,gCAoBjB;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,uBA6C/B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
async function collectModuleGraphCss(moduleGraph, pagePath) {
|
|
2
|
+
if (!pagePath) return /* @__PURE__ */ new Map();
|
|
3
|
+
const cssFiles = /* @__PURE__ */ new Map();
|
|
4
|
+
const pageModule = await moduleGraph.getModuleByUrl(pagePath, true);
|
|
5
|
+
if (!pageModule) {
|
|
6
|
+
return /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
8
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9
|
+
const walkModule = (mod) => {
|
|
10
|
+
if (!mod?.id || seen.has(mod.id)) return;
|
|
11
|
+
seen.add(mod.id);
|
|
12
|
+
if (mod?.id?.endsWith(".css")) {
|
|
13
|
+
cssFiles.set(mod?.url, mod?.id);
|
|
14
|
+
}
|
|
15
|
+
mod?.importedModules?.forEach((imp) => walkModule(imp));
|
|
16
|
+
};
|
|
17
|
+
walkModule(pageModule);
|
|
18
|
+
return cssFiles;
|
|
19
|
+
}
|
|
20
|
+
function collectManifestCss(manifest, root, pagePath, onCss) {
|
|
21
|
+
const relativePagePath = pagePath.startsWith(root + "/") ? pagePath.slice(root.length + 1) : pagePath;
|
|
22
|
+
if (!relativePagePath) return /* @__PURE__ */ new Map();
|
|
23
|
+
const cssFiles = /* @__PURE__ */ new Map();
|
|
24
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25
|
+
const walkManifestEntry = (id) => {
|
|
26
|
+
if (seen.has(id)) return;
|
|
27
|
+
seen.add(id);
|
|
28
|
+
if (id.endsWith(".css")) {
|
|
29
|
+
cssFiles.set(id, id);
|
|
30
|
+
onCss?.(id);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const entry = manifest[id];
|
|
34
|
+
if (!entry) return;
|
|
35
|
+
if (entry.css) {
|
|
36
|
+
entry.css.forEach((css) => {
|
|
37
|
+
cssFiles.set(entry.file, css);
|
|
38
|
+
onCss?.(css);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (entry.imports) {
|
|
42
|
+
entry.imports.forEach((imp) => walkManifestEntry(imp));
|
|
43
|
+
}
|
|
44
|
+
if (entry.dynamicImports) {
|
|
45
|
+
entry.dynamicImports.forEach((imp) => walkManifestEntry(imp));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (manifest[relativePagePath]) {
|
|
49
|
+
walkManifestEntry(relativePagePath);
|
|
50
|
+
}
|
|
51
|
+
return cssFiles;
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
collectManifestCss,
|
|
55
|
+
collectModuleGraphCss
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=collect-css-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect-css-manifest.js","sources":["../src/collect-css-manifest.ts"],"sourcesContent":["import type { Manifest, ModuleGraph } from \"vite\";\n\nexport async function collectModuleGraphCss(\n moduleGraph: ModuleGraph,\n pagePath: string\n) {\n if (!pagePath) return new Map<string, string>();\n\n const cssFiles = new Map<string, string>();\n const pageModule = await moduleGraph.getModuleByUrl(pagePath, true);\n if (!pageModule) {\n return new Map<string, string>();\n }\n const seen = new Set<string>();\n const walkModule = (mod: any) => {\n if (!mod?.id || seen.has(mod.id)) return;\n seen.add(mod.id);\n if (mod?.id?.endsWith(\".css\")) {\n cssFiles.set(mod?.url, mod?.id);\n }\n mod?.importedModules?.forEach((imp: any) => walkModule(imp));\n };\n walkModule(pageModule);\n return cssFiles;\n}\n\nexport function collectManifestCss(\n manifest: Manifest,\n root: string,\n pagePath: string,\n onCss?: (path: string) => void\n) {\n const relativePagePath = pagePath.startsWith(root + \"/\")\n ? pagePath.slice(root.length + 1)\n : pagePath;\n if (!relativePagePath) return new Map<string, string>();\n const cssFiles = new Map<string, string>();\n const seen = new Set<string>();\n\n const walkManifestEntry = (id: string) => {\n if (seen.has(id)) return;\n seen.add(id);\n if (id.endsWith(\".css\")) {\n cssFiles.set(id, id);\n onCss?.(id);\n return;\n }\n // Get the manifest entry\n const entry = manifest[id];\n if (!entry) return;\n\n // Add direct CSS\n if (entry.css) {\n entry.css.forEach((css: string) => {\n cssFiles.set(entry.file, css);\n onCss?.(css);\n });\n }\n\n // Walk imports recursively\n if (entry.imports) {\n entry.imports.forEach((imp: string) => walkManifestEntry(imp));\n }\n\n // Also check dynamicImports\n if (entry.dynamicImports) {\n entry.dynamicImports.forEach((imp: string) => walkManifestEntry(imp));\n }\n };\n\n if (manifest[relativePagePath]) {\n walkManifestEntry(relativePagePath);\n }\n\n return cssFiles;\n}\n"],"names":[],"mappings":"AAEsB,eAAA,sBACpB,aACA,UACA;AACA,MAAI,CAAC,SAAiB,QAAA,oBAAI,IAAoB;AAExC,QAAA,+BAAe,IAAoB;AACzC,QAAM,aAAa,MAAM,YAAY,eAAe,UAAU,IAAI;AAClE,MAAI,CAAC,YAAY;AACf,+BAAW,IAAoB;AAAA,EAAA;AAE3B,QAAA,2BAAW,IAAY;AACvB,QAAA,aAAa,CAAC,QAAa;AAC/B,QAAI,CAAC,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,EAAG;AAC7B,SAAA,IAAI,IAAI,EAAE;AACf,QAAI,KAAK,IAAI,SAAS,MAAM,GAAG;AAC7B,eAAS,IAAI,KAAK,KAAK,KAAK,EAAE;AAAA,IAAA;AAEhC,SAAK,iBAAiB,QAAQ,CAAC,QAAa,WAAW,GAAG,CAAC;AAAA,EAC7D;AACA,aAAW,UAAU;AACd,SAAA;AACT;AAEO,SAAS,mBACd,UACA,MACA,UACA,OACA;AACM,QAAA,mBAAmB,SAAS,WAAW,OAAO,GAAG,IACnD,SAAS,MAAM,KAAK,SAAS,CAAC,IAC9B;AACJ,MAAI,CAAC,iBAAyB,QAAA,oBAAI,IAAoB;AAChD,QAAA,+BAAe,IAAoB;AACnC,QAAA,2BAAW,IAAY;AAEvB,QAAA,oBAAoB,CAAC,OAAe;AACpC,QAAA,KAAK,IAAI,EAAE,EAAG;AAClB,SAAK,IAAI,EAAE;AACP,QAAA,GAAG,SAAS,MAAM,GAAG;AACd,eAAA,IAAI,IAAI,EAAE;AACnB,cAAQ,EAAE;AACV;AAAA,IAAA;AAGI,UAAA,QAAQ,SAAS,EAAE;AACzB,QAAI,CAAC,MAAO;AAGZ,QAAI,MAAM,KAAK;AACP,YAAA,IAAI,QAAQ,CAAC,QAAgB;AACxB,iBAAA,IAAI,MAAM,MAAM,GAAG;AAC5B,gBAAQ,GAAG;AAAA,MAAA,CACZ;AAAA,IAAA;AAIH,QAAI,MAAM,SAAS;AACjB,YAAM,QAAQ,QAAQ,CAAC,QAAgB,kBAAkB,GAAG,CAAC;AAAA,IAAA;AAI/D,QAAI,MAAM,gBAAgB;AACxB,YAAM,eAAe,QAAQ,CAAC,QAAgB,kBAAkB,GAAG,CAAC;AAAA,IAAA;AAAA,EAExE;AAEI,MAAA,SAAS,gBAAgB,GAAG;AAC9B,sBAAkB,gBAAgB;AAAA,EAAA;AAG7B,SAAA;AACT;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A component that emits <link> tags for CSS files during streaming.
|
|
3
|
+
* The high precedence ensures they bubble up to the document head.
|
|
4
|
+
*/
|
|
5
|
+
export declare function CssCollector({ url }: {
|
|
6
|
+
url: string;
|
|
7
|
+
}): import("react").DetailedReactHTMLElement<{
|
|
8
|
+
key: string;
|
|
9
|
+
rel: string;
|
|
10
|
+
href: string;
|
|
11
|
+
precedence: string;
|
|
12
|
+
}, HTMLElement>;
|
|
13
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE;;;;;gBAOpD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
function CssCollector({ url }) {
|
|
3
|
+
return createElement("link", {
|
|
4
|
+
key: url,
|
|
5
|
+
rel: "stylesheet",
|
|
6
|
+
href: url,
|
|
7
|
+
precedence: "high"
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
CssCollector
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../src/components.tsx"],"sourcesContent":["import { createElement } from 'react';\n\n/**\n * A component that emits <link> tags for CSS files during streaming.\n * The high precedence ensures they bubble up to the document head.\n */\nexport function CssCollector({ url }: { url: string }) {\n return createElement('link', {\n key: url,\n rel: 'stylesheet',\n href: url,\n precedence: 'high'\n });\n} "],"names":[],"mappings":";AAMgB,SAAA,aAAa,EAAE,OAAwB;AACrD,SAAO,cAAc,QAAQ;AAAA,IAC3B,KAAK;AAAA,IACL,KAAK;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,EAAA,CACb;AACH;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-dir.d.ts","sourceRoot":"","sources":["../src/copy-dir.ts"],"names":[],"mappings":"AAGA,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IACjE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;CACnC,iBAqBA"}
|
package/dist/getEnv.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConfigEnv, UserConfig } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* Get environment variables for Vite, sets defaults to ensure the server can start with BASE_URL and PUBLIC_URL
|
|
4
|
+
*
|
|
5
|
+
* @param config - Vite configuration object
|
|
6
|
+
* @param { isPreview: boolean } - Object containing a boolean indicating if the environment is for preview
|
|
7
|
+
* @returns An object containing the environment variables
|
|
8
|
+
*/
|
|
9
|
+
export declare function getEnv(config: UserConfig, configEnv: ConfigEnv): {
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
publicUrl: string;
|
|
12
|
+
port: number;
|
|
13
|
+
host: string | boolean;
|
|
14
|
+
envPrefix: string;
|
|
15
|
+
environmentName: string;
|
|
16
|
+
env: Record<string, string>;
|
|
17
|
+
define: any;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=getEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEnv.d.ts","sourceRoot":"","sources":["../src/getEnv.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIlD;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS;;;;;;;;;EAyH9D"}
|