vite-plugin-vercel 0.0.6 → 0.1.1

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 ADDED
@@ -0,0 +1,72 @@
1
+ # vite-plugin-vercel
2
+
3
+ This is a **Work In Progress** Vercel adapter for [`vite`](https://vitejs.dev/).
4
+
5
+ Its purpose is to help you bundle your application in `.vercel` folder as supported by
6
+ ([Vercel API v3](https://vercel.com/docs/build-output-api/v3)).
7
+
8
+ ## Features
9
+
10
+ - [x] [SSG/Static files support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/static-files)
11
+ - see [`prerender` config](/packages/vercel/src/types.ts#L33)
12
+ - [x] [SSR/Serverless functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/serverless-functions)
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
+ - see [`additionalEndpoints` config](/packages/vercel/src/types.ts#L54)
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](./prerender/vite-plugin-ssr.ts) for example
17
+ - [ ] [Edge functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/edge-functions)
18
+ - [ ] [Images optimization support](https://vercel.com/docs/build-output-api/v3#build-output-configuration/supported-properties/images)
19
+ - [ ] [Preview mode support](https://vercel.com/docs/build-output-api/v3#features/preview-mode)
20
+ - [x] [Advanced config override](/packages/vercel/src/types.ts#L15)
21
+ - [ ] Complete config override
22
+
23
+ ## Usage
24
+
25
+ First, make sure `ENABLE_VC_BUILD=1` is declared as an Environment Variable in your deployment configuration.
26
+
27
+ Then, install this package as a dev dependency and add it to your Vite config like this:
28
+
29
+ ```ts
30
+ import { defineConfig } from 'vite';
31
+ import vercel from 'vite-plugin-vercel';
32
+ import ssr from 'vite-plugin-ssr';
33
+
34
+ export default defineConfig({
35
+ plugins: [ssr(), vercel()],
36
+ });
37
+ ```
38
+
39
+ ### Usage with vite-plugin-ssr
40
+
41
+ [vite-plugin-ssr](https://vite-plugin-ssr.com/) will support this plugin when stable.
42
+ In the meantime, you can add experimental support yourself.
43
+
44
+ Install `@magne4000/vite-plugin-vercel-ssr` package, and update your vite config:
45
+
46
+ ```ts
47
+ // vite.config.ts
48
+ import { defineConfig } from 'vite';
49
+ import ssr from 'vite-plugin-ssr/plugin';
50
+ import vercel from 'vite-plugin-vercel';
51
+ import vercelSsr from '@magne4000/vite-plugin-vercel-ssr';
52
+
53
+ export default defineConfig(async ({ command, mode }) => {
54
+ return {
55
+ plugins: [ssr(), vercel(), vercelSsr()],
56
+ build: {
57
+ polyfillDynamicImport: false,
58
+ },
59
+ vercel: {
60
+ // Tweak what you need, check TS definition for details
61
+ },
62
+ };
63
+ });
64
+ ```
65
+
66
+ ### Config
67
+
68
+ See [TS types](/packages/vercel/src/types.ts#L15) for details.
69
+
70
+ ## Demo
71
+
72
+ https://test-vite-vercel-plugin.vercel.app/
package/dist/index.cjs CHANGED
@@ -254,7 +254,7 @@ function getEntries(resolvedConfig) {
254
254
  const parsed = import_path3.default.parse(outFilePath);
255
255
  const entry = {
256
256
  source: filePath,
257
- destination: `api/${import_path3.default.join(parsed.dir, parsed.name)}.func`
257
+ destination: `api/${import_path3.default.posix.join(parsed.dir, parsed.name)}.func`
258
258
  };
259
259
  entryPoints.push(entry);
260
260
  return entryPoints;
@@ -385,8 +385,8 @@ function vercelPlugin() {
385
385
  resolvedConfig = config;
386
386
  },
387
387
  async buildStart() {
388
- if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_FILE_SYSTEM_API) {
389
- throw new Error("Missing ENABLE_FILE_SYSTEM_API=1 to your environment variables in your project settings");
388
+ if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_VC_BUILD) {
389
+ throw new Error("Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings");
390
390
  }
391
391
  if (!resolvedConfig.build.ssr) {
392
392
  await cleanOutputDirectory(resolvedConfig);
package/dist/index.js CHANGED
@@ -231,7 +231,7 @@ function getEntries(resolvedConfig) {
231
231
  const parsed = path3.parse(outFilePath);
232
232
  const entry = {
233
233
  source: filePath,
234
- destination: `api/${path3.join(parsed.dir, parsed.name)}.func`
234
+ destination: `api/${path3.posix.join(parsed.dir, parsed.name)}.func`
235
235
  };
236
236
  entryPoints.push(entry);
237
237
  return entryPoints;
@@ -362,8 +362,8 @@ function vercelPlugin() {
362
362
  resolvedConfig = config;
363
363
  },
364
364
  async buildStart() {
365
- if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_FILE_SYSTEM_API) {
366
- throw new Error("Missing ENABLE_FILE_SYSTEM_API=1 to your environment variables in your project settings");
365
+ if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_VC_BUILD) {
366
+ throw new Error("Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings");
367
367
  }
368
368
  if (!resolvedConfig.build.ssr) {
369
369
  await cleanOutputDirectory(resolvedConfig);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "0.0.6",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -23,20 +23,20 @@
23
23
  "vite": "^2.9.9"
24
24
  },
25
25
  "devDependencies": {
26
- "@types/node": "^17.0.34",
27
- "@typescript-eslint/eslint-plugin": "^5.24.0",
28
- "@typescript-eslint/parser": "^5.24.0",
29
- "eslint": "^8.15.0",
30
- "eslint-plugin-solid": "^0.4.7",
31
- "tsup": "^5.12.8",
32
- "typescript": "^4.6.4"
26
+ "@types/node": "^17.0.36",
27
+ "@typescript-eslint/eslint-plugin": "^5.26.0",
28
+ "@typescript-eslint/parser": "^5.26.0",
29
+ "eslint": "^8.16.0",
30
+ "tsup": "^6.0.1",
31
+ "typescript": "^4.7.2",
32
+ "vite": "^2.9.9"
33
33
  },
34
34
  "dependencies": {
35
35
  "@brillout/libassert": "^0.5.6",
36
- "@vercel/routing-utils": "^1.13.2",
37
- "esbuild": "^0.14.39",
36
+ "@vercel/routing-utils": "^1.13.3",
37
+ "esbuild": "^0.14.42",
38
38
  "fast-glob": "^3.2.11",
39
- "zod": "^3.16.0"
39
+ "zod": "^3.17.3"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsup",
package/readme.md DELETED
@@ -1,28 +0,0 @@
1
- # vite-plugin-vercel
2
-
3
- This is a wip Vercel adapter for [`vite`](https://vitejs.dev/).
4
-
5
- ## Usage
6
-
7
- Install as a dev dependency and add it to your Vite config like this:
8
-
9
- ```ts
10
- import { defineConfig } from 'vite';
11
- import vercel from 'vite-plugin-vercel';
12
- import ssr from 'vite-plugin-ssr';
13
-
14
- export default defineConfig({
15
- plugins: [
16
- ssr(),
17
- vercel({
18
- dynamicRoutes: [
19
- {
20
- ssr: true,
21
- page: '/ssr',
22
- regex: '/((?!assets/)(?!api/).*)',
23
- },
24
- ],
25
- }),
26
- ],
27
- });
28
- ```