@megabudino/stack-utils 2.0.1 → 2.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/dist/proxy/vite-plugin.d.ts +15 -1
- package/dist/proxy/vite-plugin.js +29 -8
- package/package.json +2 -1
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
1
|
+
import type { Plugin, Rollup } from 'vite';
|
|
2
2
|
export declare function proxyIslands(): Plugin;
|
|
3
|
+
/**
|
|
4
|
+
* Collect every client stylesheet that must load for the islands bootstrap to
|
|
5
|
+
* paint correctly.
|
|
6
|
+
*
|
|
7
|
+
* Vite/Rollup code-splitting frequently hoists an island component into a
|
|
8
|
+
* shared chunk (for example when the same component is also imported by a
|
|
9
|
+
* normal SvelteKit route). In that case the component's `importedCss` is
|
|
10
|
+
* attributed to the shared chunk, not to the bootstrap entry chunk, so reading
|
|
11
|
+
* only the entry chunk's own `importedCss` misses the styles. We therefore walk
|
|
12
|
+
* the chunk graph transitively from the entry chunk, following each chunk's
|
|
13
|
+
* STATIC `imports` (dynamic imports are not required for first paint and could
|
|
14
|
+
* over-inject unrelated CSS), unioning the `importedCss` we find along the way.
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractClientStylesheetUrls(entryChunk: Rollup.OutputChunk, bundle: Rollup.OutputBundle, base: string): string[];
|
|
@@ -104,7 +104,7 @@ export function proxyIslands() {
|
|
|
104
104
|
throw new Error('[stack-utils proxy] failed to locate the generated islands client chunk.');
|
|
105
105
|
}
|
|
106
106
|
const clientEntryUrl = toPublicAssetUrl(clientEntryFileName, config.base);
|
|
107
|
-
const clientStylesheetUrls = extractClientStylesheetUrls(clientChunk, config.base);
|
|
107
|
+
const clientStylesheetUrls = extractClientStylesheetUrls(clientChunk, bundle, config.base);
|
|
108
108
|
await patchServerOutputFiles(config.root, clientEntryUrl, clientStylesheetUrls);
|
|
109
109
|
}
|
|
110
110
|
};
|
|
@@ -250,14 +250,35 @@ function findHooksServerFile(root) {
|
|
|
250
250
|
function toDevFsUrl(filePath) {
|
|
251
251
|
return `/@fs/${filePath.split(path.sep).join('/')}`;
|
|
252
252
|
}
|
|
253
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Collect every client stylesheet that must load for the islands bootstrap to
|
|
255
|
+
* paint correctly.
|
|
256
|
+
*
|
|
257
|
+
* Vite/Rollup code-splitting frequently hoists an island component into a
|
|
258
|
+
* shared chunk (for example when the same component is also imported by a
|
|
259
|
+
* normal SvelteKit route). In that case the component's `importedCss` is
|
|
260
|
+
* attributed to the shared chunk, not to the bootstrap entry chunk, so reading
|
|
261
|
+
* only the entry chunk's own `importedCss` misses the styles. We therefore walk
|
|
262
|
+
* the chunk graph transitively from the entry chunk, following each chunk's
|
|
263
|
+
* STATIC `imports` (dynamic imports are not required for first paint and could
|
|
264
|
+
* over-inject unrelated CSS), unioning the `importedCss` we find along the way.
|
|
265
|
+
*/
|
|
266
|
+
export function extractClientStylesheetUrls(entryChunk, bundle, base) {
|
|
254
267
|
const urls = new Set();
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
268
|
+
const visited = new Set();
|
|
269
|
+
const visit = (chunk) => {
|
|
270
|
+
if (!chunk || chunk.type !== 'chunk' || visited.has(chunk.fileName)) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
visited.add(chunk.fileName);
|
|
274
|
+
for (const fileName of chunk.viteMetadata?.importedCss ?? []) {
|
|
275
|
+
urls.add(toPublicAssetUrl(fileName, base));
|
|
276
|
+
}
|
|
277
|
+
for (const importFileName of chunk.imports ?? []) {
|
|
278
|
+
visit(bundle[importFileName]);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
visit(entryChunk);
|
|
261
282
|
return [...urls];
|
|
262
283
|
}
|
|
263
284
|
async function patchServerOutputFiles(root, clientEntryUrl, clientStylesheetUrls) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@megabudino/stack-utils",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Reusable utilities for a SvelteKit stack, including a reverse proxy and static image pipeline",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"cheerio": "^1.2.0",
|
|
44
44
|
"node-addon-api": "^8.8.0",
|
|
45
|
+
"node-gyp": "^12.3.0",
|
|
45
46
|
"sharp": "^0.34.5"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|