Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Vite plugin adapter API to presets #8620

Merged
merged 28 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dd64014
Support all config values in Vite adapter
markdalgleish Jan 29, 2024
b877312
fix lint error
markdalgleish Jan 29, 2024
6f3589f
Merge branch 'dev' into markdalgleish/adapter-config
markdalgleish Jan 29, 2024
a8a444c
move `loadContext` to adapter
markdalgleish Jan 30, 2024
0feec81
add changeset
markdalgleish Jan 30, 2024
7fecd63
fix test
markdalgleish Jan 30, 2024
c3890a9
Merge branch 'dev' into markdalgleish/adapter-config
markdalgleish Jan 30, 2024
f7174cd
remove loadContext option docs
markdalgleish Jan 30, 2024
9d75f16
clean test
markdalgleish Jan 30, 2024
258b751
add remixConfig key on adapter config
markdalgleish Jan 30, 2024
8fbc7f9
flesh out adapter smoke tests
markdalgleish Jan 30, 2024
8e0e4ef
workaround for minimatch windows issue
markdalgleish Jan 30, 2024
ab91fbc
tweak changeset
markdalgleish Jan 30, 2024
60bbe5d
fix formatting
markdalgleish Jan 30, 2024
2ed846e
fix formatting
markdalgleish Jan 30, 2024
471d9ac
Merge branch 'dev' into markdalgleish/adapter-config
markdalgleish Jan 30, 2024
1a7be66
try different glob
markdalgleish Jan 30, 2024
1d71024
tweak test
markdalgleish Jan 30, 2024
eaaa559
tweak adapter API, remove loadContext and viteConfig options
markdalgleish Jan 30, 2024
1fae09b
switch to `presets` array, add `remixConfigResolved` preset hook
markdalgleish Jan 31, 2024
f386c97
exclude presets key from preset remix config
markdalgleish Jan 31, 2024
b302598
simplify config merge function, fix preset merge order
markdalgleish Jan 31, 2024
6dcae68
fix default handling, clean up
markdalgleish Jan 31, 2024
63bc3f6
remove args from `remixConfig` preset hook
markdalgleish Jan 31, 2024
829d1ca
add required name property to preset
markdalgleish Jan 31, 2024
ae67b55
ensure test case handles absolute paths
markdalgleish Jan 31, 2024
9fafb11
Merge branch 'dev' into markdalgleish/adapter-config
pcattori Jan 31, 2024
08ebfc2
Merge branch 'dev' into markdalgleish/adapter-config
pcattori Jan 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/ninety-baboons-leave.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@remix-run/dev": patch
---

Vite: Add `adapter` option to support modifying the build output and/or development environment for different hosting providers.
Vite: Add `presets` option to ease integration with different platforms and tools.
5 changes: 5 additions & 0 deletions .changeset/quiet-adults-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Vite: Add `buildEnd` hook
36 changes: 24 additions & 12 deletions docs/future/vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,23 @@ The following subset of Remix config options are supported:

The Vite plugin also accepts the following additional options:

#### adapter
#### buildDirectory

A function for adapting the build output and/or development environment for different hosting providers.
The path to the build directory, relative to the project root. Defaults to
`"build"`.

#### buildDirectory
#### buildEnd

The path to the build directory, relative to the project root. Defaults to `"build"`.
A function that is called after the full Remix build is complete.

#### manifest

Whether to write a `.remix/manifest.json` file to the build directory. Defaults to `false`.
Whether to write a `.remix/manifest.json` file to the build directory. Defaults
to `false`.

#### presets

An array of Remix config presets to ease integration with different platforms and tools.

#### serverBuildFile

Expand Down Expand Up @@ -116,19 +122,19 @@ wrangler pages dev ./build/client
```

While Vite provides a better development experience, Wrangler provides closer emulation of the Cloudflare environment by running your server code in [Cloudflare's `workerd` runtime][cloudflare-workerd] instead of Node.
To simulate the Cloudflare environment in Vite, Wrangler provides [Node proxies for resource bindings][wrangler-getbindingsproxy] which are automatically available when using the Remix Cloudflare adapter:
To simulate the Cloudflare environment in Vite, Wrangler provides [Node proxies for resource bindings][wrangler-getbindingsproxy] which are automatically available when using the Remix Cloudflare preset:

```ts filename=vite.config.ts lines=[3,10]
import {
unstable_vitePlugin as remix,
unstable_vitePluginAdapterCloudflare as cloudflare,
unstable_vitePluginPresetCloudflare as cloudflare,
} from "@remix-run/dev";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [
remix({
adapter: cloudflare(),
presets: [cloudflare()],
}),
],
});
Expand Down Expand Up @@ -413,19 +419,25 @@ The Remix Vite plugin only officially supports [Cloudflare Pages][cloudflare-pag

</docs-warning>

👉 **Add the Cloudflare adapter to your Vite config**
👉 **In your Vite config, add `"workerd"` and `"worker"` to Vite's
`ssr.resolve.externalConditions` option and add the Cloudflare Remix preset**

```ts filename=vite.config.ts lines=[3,10]
```ts filename=vite.config.ts lines=[3,8-12,15]
import {
unstable_vitePlugin as remix,
unstable_vitePluginAdapterCloudflare as cloudflare,
unstable_vitePluginPresetCloudflare as cloudflare,
} from "@remix-run/dev";
import { defineConfig } from "vite";

export default defineConfig({
ssr: {
resolve: {
externalConditions: ["workerd", "worker"],
},
},
plugins: [
remix({
adapter: cloudflare(),
presets: [cloudflare()],
}),
],
});
Expand Down
8 changes: 8 additions & 0 deletions integration/helpers/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ export const VITE_CONFIG = async (args: {
pluginOptions?: string;
vitePlugins?: string;
viteManifest?: boolean;
viteSsrResolveExternalConditions?: string[];
}) => {
let hmrPort = await getPort();
return String.raw`
import { defineConfig } from "vite";
import { unstable_vitePlugin as remix } from "@remix-run/dev";

export default defineConfig({
ssr: {
resolve: {
externalConditions: ${JSON.stringify(
args.viteSsrResolveExternalConditions ?? []
)},
},
},
server: {
port: ${args.port},
strictPort: true,
Expand Down
125 changes: 0 additions & 125 deletions integration/vite-adapter-test.ts

This file was deleted.

3 changes: 2 additions & 1 deletion integration/vite-cloudflare-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ test.describe("Vite / cloudflare", async () => {
),
"vite.config.ts": await VITE_CONFIG({
port,
pluginOptions: `{ adapter: (await import("@remix-run/dev")).unstable_vitePluginAdapterCloudflare() }`,
viteSsrResolveExternalConditions: ["workerd", "worker"],
pluginOptions: `{ presets: [(await import("@remix-run/dev")).unstable_vitePluginPresetCloudflare()] }`,
}),
"functions/[[page]].ts": `
import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages";
Expand Down
Loading
Loading