Commit Graph

3 Commits

Author SHA1 Message Date
Nathan Rajlich
1333071a3a Remix Vite plugin support (#11031)
Adds support for Remix apps which use the new Remix Vite plugin.

* The vanilla Remix + Vite template deploys correctly out-of-the-box,
however only a single Node.js function will be used, and a warning will
be printed saying to configure the `vercelPreset()` Preset.
* When used in conjunction with the `vercelPreset()` Preset
(https://github.com/vercel/remix/pull/81), allows for the application to
utilize Vercel-specific features, like per-route `export const config`
configuration, including multi-runtime (Node.js / Edge runtimes) within
the same app.

## To test this today

1. Generate a Remix + Vite project from the template:
    ```
    npx create-remix@latest --template remix-run/remix/templates/vite
    ```
1. Install `@vercel/remix`:
    ```
    npm i --save-dev @vercel/remix
    ```
1. **(Before Remix v2.8.0 is released)** - Update the `@remix-run/dev`
dependency to use the "pre" tag which contains [a bug
fix](https://github.com/remix-run/remix/pull/8864):
    ```
    npm i --save--dev @remix-run/dev@pre @remix-run/serve@pre
    ```
1. Configure the `vercelPreset()` in the `vite.config.ts` file:
    ```diff
    --- a/vite.config.ts
    +++ b/vite.config.ts
    @@ -1,10 +1,11 @@
     import { vitePlugin as remix } from "@remix-run/dev";
     import { installGlobals } from "@remix-run/node";
     import { defineConfig } from "vite";
    +import { vercelPreset } from "@vercel/remix/vite";
     import tsconfigPaths from "vite-tsconfig-paths";
    
     installGlobals();
    
     export default defineConfig({
    -  plugins: [remix(), tsconfigPaths()],
    +  plugins: [remix({ presets: [vercelPreset()] }), tsconfigPaths()],
     });
    ```
1. Create a new Vercel Project in the dashboard, and ensure the Vercel
preset is set to "Remix" in the Project Settings. The autodetection will
work correctly once this PR is merged, but for now it gets incorrectly
detected as "Vite" preset.
* **Hint**: You can create a new empty Project by running the `vercel
link` command.
<img width="545" alt="Screenshot 2024-02-27 at 10 37 11"
src="https://github.com/vercel/vercel/assets/71256/f46baf57-5d97-4bde-9529-c9165632cb30">
1. Deploy to Vercel, setting the `VERCEL_CLI_VERSION` environment
variable to use the changes in this PR:
    ```
vercel deploy -b
VERCEL_CLI_VERSION=https://vercel-git-tootallnate-zero-1217-research-remix-v-next-vite.vercel.sh/tarballs/vercel.tgz
    ```
2024-02-28 11:22:05 -06:00
Nathan Rajlich
d0d0520111 [next] Use "esbuild" to build package (#10482)
### Before

```
$ time pnpm run build

> @vercel/next@4.0.6 build /Users/nrajlich/Code/vercel/vercel/packages/next
> node build.js

ncc: Version 0.24.0
ncc: Compiling file index.js
ncc: Using typescript@4.9.5 (local user-provided)
1506kB  dist/main/index.js
1506kB  [3345ms] - ncc 0.24.0

real    0m5.210s
user    0m9.083s
sys     0m0.506s

$ ls -l dist/
total 1700
-rw-r--r-- 1 nrajlich staff    2176 Sep 20 15:18 ___get-nextjs-edge-function.js
-rw-r--r-- 1 nrajlich staff    3283 Sep 20 15:18 create-serverless-config.js
drwxr-xr-x 6 nrajlich staff     192 Sep 20 15:18 edge-function-source/
-rw-r--r-- 1 nrajlich staff 1542314 Sep 20 15:18 index.js
-rw-r--r-- 1 nrajlich staff     728 Sep 20 15:18 legacy-launcher.js
-rw-r--r-- 1 nrajlich staff    6807 Sep 20 15:18 legacy-versions.js
-rw-r--r-- 1 nrajlich staff   66662 Sep 20 15:18 server-build.js
-rw-r--r-- 1 nrajlich staff    1583 Sep 20 15:18 server-launcher.js
-rw-r--r-- 1 nrajlich staff    5167 Sep 20 15:18 sourcemapped.js
-rw-r--r-- 1 nrajlich staff    1003 Sep 20 15:18 templated-launcher-shared.js
-rw-r--r-- 1 nrajlich staff     799 Sep 20 15:18 templated-launcher.js
-rw-r--r-- 1 nrajlich staff   83876 Sep 20 15:18 utils.js

$ pnpm pack && ls -lh vercel-next-4.0.6.tgz 
-rw-r--r-- 1 nrajlich staff 373K Sep 20 15:19 vercel-next-4.0.6.tgz
```

### After

```
$ time pnpm run build

> @vercel/next@4.0.6 build /Users/nrajlich/Code/vercel/vercel/packages/next
> node build.mjs

real    0m1.144s
user    0m0.550s
sys     0m0.171s

$ ls -l dist/
total 540
-rw-r--r-- 1 nrajlich staff   2176 Sep 20 15:15 ___get-nextjs-edge-function.js
-rw-r--r-- 1 nrajlich staff 528575 Sep 20 15:15 index.js
-rw-r--r-- 1 nrajlich staff   1680 Sep 20 15:15 legacy-launcher.js
-rw-r--r-- 1 nrajlich staff    901 Sep 20 15:15 server-launcher.js
-rw-r--r-- 1 nrajlich staff    532 Sep 20 15:15 templated-launcher-shared.js
-rw-r--r-- 1 nrajlich staff    316 Sep 20 15:15 templated-launcher.js

$ pnpm pack && ls -lh vercel-next-4.0.6.tgz 
-rw-r--r-- 1 nrajlich staff 104K Sep 20 15:15 vercel-next-4.0.6.tgz
```
2023-09-20 20:01:03 +00:00
Nathan Rajlich
b265e13d40 [static-build] Use esbuild (#10462)
Switch to using esbuild to compile + bundle `@vercel/static-build`.
2023-09-08 19:39:12 +00:00