vite-plugin-vercel 0.1.1 → 0.1.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/README.md +2 -2
- package/dist/index.cjs +25 -1
- package/dist/index.js +25 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
This is a **Work In Progress** Vercel adapter for [`vite`](https://vitejs.dev/).
|
|
4
4
|
|
|
5
5
|
Its purpose is to help you bundle your application in `.vercel` folder as supported by
|
|
6
|
-
|
|
6
|
+
[Vercel API v3](https://vercel.com/docs/build-output-api/v3).
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ Its purpose is to help you bundle your application in `.vercel` folder as suppor
|
|
|
13
13
|
- `.[jt]s` files under the `<root>/api` folder of your project are automatically bundled as Serverless functions under `.vercel/output/functions/api/*.func`
|
|
14
14
|
- see [`additionalEndpoints` config](/packages/vercel/src/types.ts#L54)
|
|
15
15
|
- [x] [ISR/Prerender functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/prerender-functions)
|
|
16
|
-
- see [`isr` config](/packages/vercel/src/types.ts#L81). Also see implementation of [vite-plugin-ssr](
|
|
16
|
+
- see [`isr` config](/packages/vercel/src/types.ts#L81). Also see implementation of [vite-plugin-ssr](/packages/vite-plugin-ssr/vite-plugin-ssr.ts) for example
|
|
17
17
|
- [ ] [Edge functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/edge-functions)
|
|
18
18
|
- [ ] [Images optimization support](https://vercel.com/docs/build-output-api/v3#build-output-configuration/supported-properties/images)
|
|
19
19
|
- [ ] [Preview mode support](https://vercel.com/docs/build-output-api/v3#features/preview-mode)
|
package/dist/index.cjs
CHANGED
|
@@ -375,6 +375,7 @@ async function getIsrConfig(resolvedConfig) {
|
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
// src/index.ts
|
|
378
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
378
379
|
function vercelPlugin() {
|
|
379
380
|
let resolvedConfig;
|
|
380
381
|
return {
|
|
@@ -398,12 +399,13 @@ function vercelPlugin() {
|
|
|
398
399
|
var _a;
|
|
399
400
|
if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr))
|
|
400
401
|
return;
|
|
402
|
+
const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
|
|
401
403
|
const overrides = await execPrerender(resolvedConfig);
|
|
402
404
|
await buildEndpoints(resolvedConfig);
|
|
403
405
|
const rewrites = await buildPrerenderConfigs(resolvedConfig);
|
|
404
406
|
await writeConfig(resolvedConfig, {
|
|
405
407
|
routes: [{ handle: "filesystem" }, ...rewrites],
|
|
406
|
-
overrides
|
|
408
|
+
overrides: __spreadValues(__spreadValues({}, userOverrides), overrides)
|
|
407
409
|
});
|
|
408
410
|
}
|
|
409
411
|
};
|
|
@@ -417,6 +419,28 @@ async function cleanOutputDirectory(resolvedConfig) {
|
|
|
417
419
|
force: true
|
|
418
420
|
});
|
|
419
421
|
}
|
|
422
|
+
async function computeStaticHtmlOverrides(resolvedConfig) {
|
|
423
|
+
const staticAbsolutePath = getOutput(resolvedConfig, "static");
|
|
424
|
+
const files = await getStaticHtmlFiles(resolvedConfig, staticAbsolutePath);
|
|
425
|
+
return files.reduce((acc, curr) => {
|
|
426
|
+
const relPath = import_path5.default.relative(staticAbsolutePath, curr);
|
|
427
|
+
const parsed = import_path5.default.parse(relPath);
|
|
428
|
+
const pathJoined = import_path5.default.join(parsed.dir, parsed.name);
|
|
429
|
+
acc[relPath] = {
|
|
430
|
+
path: pathJoined
|
|
431
|
+
};
|
|
432
|
+
return acc;
|
|
433
|
+
}, {});
|
|
434
|
+
}
|
|
435
|
+
async function getStaticHtmlFiles(resolvedConfig, src) {
|
|
436
|
+
const entries = await import_promises5.default.readdir(src, { withFileTypes: true });
|
|
437
|
+
const htmlFiles = [];
|
|
438
|
+
for (const entry of entries) {
|
|
439
|
+
const srcPath = import_path5.default.join(src, entry.name);
|
|
440
|
+
entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(resolvedConfig, srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
|
|
441
|
+
}
|
|
442
|
+
return htmlFiles;
|
|
443
|
+
}
|
|
420
444
|
function allPlugins() {
|
|
421
445
|
return [vercelPlugin()];
|
|
422
446
|
}
|
package/dist/index.js
CHANGED
|
@@ -352,6 +352,7 @@ async function getIsrConfig(resolvedConfig) {
|
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
// src/index.ts
|
|
355
|
+
import path5 from "path";
|
|
355
356
|
function vercelPlugin() {
|
|
356
357
|
let resolvedConfig;
|
|
357
358
|
return {
|
|
@@ -375,12 +376,13 @@ function vercelPlugin() {
|
|
|
375
376
|
var _a;
|
|
376
377
|
if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr))
|
|
377
378
|
return;
|
|
379
|
+
const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
|
|
378
380
|
const overrides = await execPrerender(resolvedConfig);
|
|
379
381
|
await buildEndpoints(resolvedConfig);
|
|
380
382
|
const rewrites = await buildPrerenderConfigs(resolvedConfig);
|
|
381
383
|
await writeConfig(resolvedConfig, {
|
|
382
384
|
routes: [{ handle: "filesystem" }, ...rewrites],
|
|
383
|
-
overrides
|
|
385
|
+
overrides: __spreadValues(__spreadValues({}, userOverrides), overrides)
|
|
384
386
|
});
|
|
385
387
|
}
|
|
386
388
|
};
|
|
@@ -394,6 +396,28 @@ async function cleanOutputDirectory(resolvedConfig) {
|
|
|
394
396
|
force: true
|
|
395
397
|
});
|
|
396
398
|
}
|
|
399
|
+
async function computeStaticHtmlOverrides(resolvedConfig) {
|
|
400
|
+
const staticAbsolutePath = getOutput(resolvedConfig, "static");
|
|
401
|
+
const files = await getStaticHtmlFiles(resolvedConfig, staticAbsolutePath);
|
|
402
|
+
return files.reduce((acc, curr) => {
|
|
403
|
+
const relPath = path5.relative(staticAbsolutePath, curr);
|
|
404
|
+
const parsed = path5.parse(relPath);
|
|
405
|
+
const pathJoined = path5.join(parsed.dir, parsed.name);
|
|
406
|
+
acc[relPath] = {
|
|
407
|
+
path: pathJoined
|
|
408
|
+
};
|
|
409
|
+
return acc;
|
|
410
|
+
}, {});
|
|
411
|
+
}
|
|
412
|
+
async function getStaticHtmlFiles(resolvedConfig, src) {
|
|
413
|
+
const entries = await fs5.readdir(src, { withFileTypes: true });
|
|
414
|
+
const htmlFiles = [];
|
|
415
|
+
for (const entry of entries) {
|
|
416
|
+
const srcPath = path5.join(src, entry.name);
|
|
417
|
+
entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(resolvedConfig, srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
|
|
418
|
+
}
|
|
419
|
+
return htmlFiles;
|
|
420
|
+
}
|
|
397
421
|
function allPlugins() {
|
|
398
422
|
return [vercelPlugin()];
|
|
399
423
|
}
|