vite-plugin-vercel 0.3.2 → 0.3.4

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 CHANGED
@@ -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#L62)
15
15
  - [x] [ISR/Prerender functions support](https://vercel.com/docs/build-output-api/v3/primitives#prerender-functions)
16
- - see [`isr` config](/packages/vercel/src/types.ts#L89). Also see implementation of [vite-plugin-ssr](/packages/vike-integration/vite-plugin-ssr.ts) for example
16
+ - see [`isr` config](/packages/vercel/src/types.ts#L89). Also see implementation of [vike](/packages/vike-integration/vike.ts) for example
17
17
  - [x] [Edge functions support](https://vercel.com/docs/build-output-api/v3/primitives#edge-functions)
18
18
  - [ ] [Images optimization support](https://vercel.com/docs/build-output-api/v3/configuration#images)
19
19
  - [ ] [Preview mode support](https://vercel.com/docs/build-output-api/v3/features#preview-mode)
@@ -37,9 +37,9 @@ export default defineConfig({
37
37
  });
38
38
  ```
39
39
 
40
- ## Usage with vite-plugin-ssr
40
+ ## Usage with vike
41
41
 
42
- [vite-plugin-ssr](https://vite-plugin-ssr.com/) is supported through [@vite-plugin-vercel/vike](/packages/vike-integration/README.md) plugin.
42
+ [vike](https://vike.dev/) is supported through [@vite-plugin-vercel/vike](/packages/vike-integration/README.md) plugin.
43
43
 
44
44
  You only need to install `@vite-plugin-vercel/vike`, the Vite config stays the same as above.
45
45
 
@@ -47,16 +47,16 @@ You only need to install `@vite-plugin-vercel/vike`, the Vite config stays the s
47
47
  > `@vite-plugin-vercel/vike` supersedes the old `@magne4000/vite-plugin-vercel-ssr` package.
48
48
  > As such, you should remove `@magne4000/vite-plugin-vercel-ssr` from your package.json and vite config file.
49
49
 
50
- ### vite-plugin-ssr V1 design
50
+ ### vike V1 design
51
51
 
52
- `vite-plugin-vercel` fully supports [vite-plugin-ssr V1 design](https://vite-plugin-ssr.com/migration/v1-design),
53
- and thus you can leverage [config files](https://vite-plugin-ssr.com/config) to customize ISR configuration:
52
+ `vite-plugin-vercel` fully supports [vike V1 design](https://vike.dev/migration/v1-design),
53
+ and thus you can leverage [config files](https://vike.dev/config) to customize ISR configuration:
54
54
 
55
55
  ```ts
56
56
  // /pages/product/+config.h.ts
57
57
 
58
58
  import Page from './Page';
59
- import type { Config } from 'vite-plugin-ssr/types';
59
+ import type { Config } from 'vike/types';
60
60
 
61
61
  // Customize ISR config for this page
62
62
  export default {
@@ -64,13 +64,13 @@ export default {
64
64
  } satisfies Config;
65
65
  ```
66
66
 
67
- You will also need to extend the [renderer config](https://vite-plugin-ssr.com/config#renderer) so that `vite-plugin-ssr` is aware of the new parameter:
67
+ You will also need to extend the [renderer config](https://vike.dev/config#renderer) so that `vike` is aware of the new parameter:
68
68
 
69
69
  ```ts
70
70
  // /renderer/+config.h.ts
71
71
 
72
72
  import config from '@vite-plugin-vercel/vike/config';
73
- import type { Config } from 'vite-plugin-ssr/types';
73
+ import type { Config } from 'vike/types';
74
74
 
75
75
  export default {
76
76
  extends: config,
@@ -105,7 +105,7 @@ export default defineConfig({
105
105
  * Defaults to `false`, which disables prerendering.
106
106
  */
107
107
  prerender(resolvedConfig) {
108
- // Check `/packages/vite-plugin-ssr/vite-plugin-ssr.ts` `prerender` for an example
108
+ // Check `/packages/vike/vike.ts` `prerender` for an example
109
109
  },
110
110
  /**
111
111
  * See https://vercel.com/docs/projects/project-configuration#rewrites
@@ -160,7 +160,7 @@ export default defineConfig({
160
160
  *
161
161
  * Can be an object or a function returning an object (or a Promise of an object).
162
162
  *
163
- * Check `/packages/vite-plugin-ssr/vite-plugin-ssr.ts` `vitePluginVercelVpsIsrPlugin` for advanced usage.
163
+ * Check `/packages/vike/vike.ts` `vitePluginVercelVpsIsrPlugin` for advanced usage.
164
164
  */
165
165
  isr: {
166
166
  // `symlink: 'ssr_'` means that a function is available under `.vercel/output/functions/ssr_.func`
package/dist/index.cjs CHANGED
@@ -284,13 +284,40 @@ function getEntries(resolvedConfig) {
284
284
  return entryPoints;
285
285
  }, getAdditionalEndpoints(resolvedConfig));
286
286
  }
287
+ var wasmPlugin = {
288
+ name: "wasm",
289
+ setup(build2) {
290
+ build2.onResolve({ filter: /\.wasm/ }, (args) => {
291
+ return {
292
+ path: args.path.replace(/\.wasm\?module$/i, ".wasm"),
293
+ external: true
294
+ };
295
+ });
296
+ }
297
+ };
298
+ var vercelOgPlugin = (ctx) => {
299
+ return {
300
+ name: "vercel-og",
301
+ setup(build2) {
302
+ build2.onResolve({ filter: /@vercel\/og/ }, () => {
303
+ ctx.found = true;
304
+ return void 0;
305
+ });
306
+ build2.onLoad({ filter: /@vercel\/og/ }, (args) => {
307
+ ctx.index = args.path;
308
+ return void 0;
309
+ });
310
+ }
311
+ };
312
+ };
287
313
  var standardBuildOptions = {
288
314
  bundle: true,
289
315
  target: "es2020",
290
316
  format: "cjs",
291
317
  platform: "node",
292
318
  logLevel: "info",
293
- minify: true
319
+ minify: true,
320
+ plugins: [wasmPlugin]
294
321
  };
295
322
  async function buildFn(resolvedConfig, entry, buildOptions) {
296
323
  assert(
@@ -329,8 +356,25 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
329
356
  "import",
330
357
  "require"
331
358
  ];
359
+ options.format = "esm";
332
360
  }
361
+ const ctx = { found: false, index: "" };
362
+ options.plugins.push(vercelOgPlugin(ctx));
333
363
  await (0, import_esbuild.build)(options);
364
+ if (ctx.found && ctx.index) {
365
+ const dir = (0, import_path3.dirname)(ctx.index);
366
+ const externalFiles = await (0, import_fast_glob.default)(`${dir}/*.{ttf,wasm}`);
367
+ for (const f of externalFiles) {
368
+ await (0, import_promises2.copyFile)(
369
+ f,
370
+ import_path3.default.join(
371
+ getOutput(resolvedConfig, "functions"),
372
+ entry.destination,
373
+ (0, import_path3.basename)(f)
374
+ )
375
+ );
376
+ }
377
+ }
334
378
  await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
335
379
  }
336
380
  async function writeVcConfig(resolvedConfig, destination, edge) {
@@ -557,11 +601,17 @@ async function getStaticHtmlFiles(src) {
557
601
  }
558
602
  async function tryImportVpvv() {
559
603
  try {
560
- await import("vite-plugin-ssr/plugin");
604
+ await import("vike/plugin");
561
605
  const vpvv = await import("@vite-plugin-vercel/vike");
562
606
  return vpvv.default();
563
607
  } catch (e) {
564
- return null;
608
+ try {
609
+ await import("vite-plugin-ssr/plugin");
610
+ const vpvv = await import("@vite-plugin-vercel/vike");
611
+ return vpvv.default();
612
+ } catch (e2) {
613
+ return null;
614
+ }
565
615
  }
566
616
  }
567
617
  function allPlugins(options = {}) {
package/dist/index.js CHANGED
@@ -175,7 +175,7 @@ async function writeConfig(resolvedConfig, rewrites, overrides) {
175
175
 
176
176
  // src/build.ts
177
177
  import glob from "fast-glob";
178
- import path3 from "path";
178
+ import path3, { basename, dirname } from "path";
179
179
  import { build } from "esbuild";
180
180
 
181
181
  // src/assert.ts
@@ -217,7 +217,7 @@ var vercelOutputVcConfigSchema = z2.union([
217
217
  ]);
218
218
 
219
219
  // src/build.ts
220
- import fs2 from "fs/promises";
220
+ import fs2, { copyFile } from "fs/promises";
221
221
  function getAdditionalEndpoints(resolvedConfig) {
222
222
  var _a;
223
223
  return (((_a = resolvedConfig.vercel) == null ? void 0 : _a.additionalEndpoints) ?? []).map((e) => ({
@@ -250,13 +250,40 @@ function getEntries(resolvedConfig) {
250
250
  return entryPoints;
251
251
  }, getAdditionalEndpoints(resolvedConfig));
252
252
  }
253
+ var wasmPlugin = {
254
+ name: "wasm",
255
+ setup(build2) {
256
+ build2.onResolve({ filter: /\.wasm/ }, (args) => {
257
+ return {
258
+ path: args.path.replace(/\.wasm\?module$/i, ".wasm"),
259
+ external: true
260
+ };
261
+ });
262
+ }
263
+ };
264
+ var vercelOgPlugin = (ctx) => {
265
+ return {
266
+ name: "vercel-og",
267
+ setup(build2) {
268
+ build2.onResolve({ filter: /@vercel\/og/ }, () => {
269
+ ctx.found = true;
270
+ return void 0;
271
+ });
272
+ build2.onLoad({ filter: /@vercel\/og/ }, (args) => {
273
+ ctx.index = args.path;
274
+ return void 0;
275
+ });
276
+ }
277
+ };
278
+ };
253
279
  var standardBuildOptions = {
254
280
  bundle: true,
255
281
  target: "es2020",
256
282
  format: "cjs",
257
283
  platform: "node",
258
284
  logLevel: "info",
259
- minify: true
285
+ minify: true,
286
+ plugins: [wasmPlugin]
260
287
  };
261
288
  async function buildFn(resolvedConfig, entry, buildOptions) {
262
289
  assert(
@@ -295,8 +322,25 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
295
322
  "import",
296
323
  "require"
297
324
  ];
325
+ options.format = "esm";
298
326
  }
327
+ const ctx = { found: false, index: "" };
328
+ options.plugins.push(vercelOgPlugin(ctx));
299
329
  await build(options);
330
+ if (ctx.found && ctx.index) {
331
+ const dir = dirname(ctx.index);
332
+ const externalFiles = await glob(`${dir}/*.{ttf,wasm}`);
333
+ for (const f of externalFiles) {
334
+ await copyFile(
335
+ f,
336
+ path3.join(
337
+ getOutput(resolvedConfig, "functions"),
338
+ entry.destination,
339
+ basename(f)
340
+ )
341
+ );
342
+ }
343
+ }
300
344
  await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
301
345
  }
302
346
  async function writeVcConfig(resolvedConfig, destination, edge) {
@@ -523,11 +567,17 @@ async function getStaticHtmlFiles(src) {
523
567
  }
524
568
  async function tryImportVpvv() {
525
569
  try {
526
- await import("vite-plugin-ssr/plugin");
570
+ await import("vike/plugin");
527
571
  const vpvv = await import("@vite-plugin-vercel/vike");
528
572
  return vpvv.default();
529
573
  } catch (e) {
530
- return null;
574
+ try {
575
+ await import("vite-plugin-ssr/plugin");
576
+ const vpvv = await import("@vite-plugin-vercel/vike");
577
+ return vpvv.default();
578
+ } catch (e2) {
579
+ return null;
580
+ }
531
581
  }
532
582
  }
533
583
  function allPlugins(options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -21,14 +21,14 @@
21
21
  "license": "MIT",
22
22
  "peerDependencies": {
23
23
  "vite": "^4.2.0",
24
- "vite-plugin-ssr": "*",
25
- "@vite-plugin-vercel/vike": "0.3.3"
24
+ "vike": "*",
25
+ "@vite-plugin-vercel/vike": "0.4.0"
26
26
  },
27
27
  "peerDependenciesMeta": {
28
28
  "@vite-plugin-vercel/vike": {
29
29
  "optional": true
30
30
  },
31
- "vite-plugin-ssr": {
31
+ "vike": {
32
32
  "optional": true
33
33
  }
34
34
  },
@@ -40,8 +40,8 @@
40
40
  "tsup": "^7.2.0",
41
41
  "typescript": "^5.2.2",
42
42
  "vite": "^4.4.9",
43
- "vite-plugin-ssr": "^0.4.141",
44
- "@vite-plugin-vercel/vike": "0.3.3"
43
+ "vike": "^0.4.142",
44
+ "@vite-plugin-vercel/vike": "0.4.0"
45
45
  },
46
46
  "dependencies": {
47
47
  "@brillout/libassert": "^0.5.8",