-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(remix-dev/vite): change build output paths #8077
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
Changes from all commits
61c96e9
963d854
3ab2c51
e926bb9
e88e479
039f8df
c8f5a2c
98a2d86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| "@remix-run/dev": patch | ||
| --- | ||
|
|
||
| Change Vite build output paths to fix a conflict between how Vite and the Remix compiler each manage the `public` directory. | ||
|
|
||
| **This is a breaking change for projects using the unstable Vite plugin.** | ||
|
|
||
| The server is now compiled into `build/server` rather than `build`, and the client is now compiled into `build/client` rather than `public`. | ||
|
|
||
| For more information on the changes and guidance on how to migrate your project, refer to the updated [Remix Vite documentation](https://remix.run/docs/en/main/future/vite). |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,14 +45,34 @@ const supportedRemixConfigKeys = [ | |
| "serverModuleFormat", | ||
| ] as const satisfies ReadonlyArray<keyof RemixUserConfig>; | ||
| type SupportedRemixConfigKey = typeof supportedRemixConfigKeys[number]; | ||
|
|
||
| export type RemixVitePluginOptions = Pick< | ||
| RemixUserConfig, | ||
| SupportedRemixConfigKey | ||
| > & { | ||
| legacyCssImports?: boolean; | ||
| type SupportedRemixConfig = Pick<RemixUserConfig, SupportedRemixConfigKey>; | ||
|
|
||
| // We need to provide different JSDoc comments in some cases due to differences | ||
| // between the Remix config and the Vite plugin. | ||
| type RemixConfigJsdocOverrides = { | ||
| /** | ||
| * The path to the browser build, relative to the project root. Defaults to | ||
| * `"build/client"`. | ||
| */ | ||
| assetsBuildDirectory?: SupportedRemixConfig["assetsBuildDirectory"]; | ||
| /** | ||
| * The URL prefix of the browser build with a trailing slash. Defaults to | ||
| * `"/"`. This is the path the browser will use to find assets. | ||
| */ | ||
| publicPath?: SupportedRemixConfig["publicPath"]; | ||
| /** | ||
| * The path to the server build file, relative to the project. This file | ||
| * should end in a `.js` extension and should be deployed to your server. | ||
| * Defaults to `"build/server/index.js"`. | ||
| */ | ||
| serverBuildPath?: SupportedRemixConfig["serverBuildPath"]; | ||
| }; | ||
|
|
||
| export type RemixVitePluginOptions = RemixConfigJsdocOverrides & | ||
| Omit<SupportedRemixConfig, keyof RemixConfigJsdocOverrides> & { | ||
| legacyCssImports?: boolean; | ||
| }; | ||
|
|
||
| type ResolvedRemixVitePluginConfig = Pick< | ||
| ResolvedRemixConfig, | ||
| | "appDirectory" | ||
|
|
@@ -255,12 +275,20 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => { | |
|
|
||
| let resolvePluginConfig = | ||
| async (): Promise<ResolvedRemixVitePluginConfig> => { | ||
| let defaults: Partial<RemixVitePluginOptions> = { | ||
| serverBuildPath: "build/server/index.js", | ||
| assetsBuildDirectory: "build/client", | ||
| publicPath: "/", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice change! I think remix still doesn't support custom basename in general, but I was wondering if it makes sense to deprecate For the reference: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a really good point! I'll keep this in mind when looking at custom |
||
| }; | ||
|
|
||
| let config = { | ||
| ...defaults, | ||
| ...pick(options, supportedRemixConfigKeys), // Avoid leaking any config options that the Vite plugin doesn't support | ||
| }; | ||
|
|
||
| let rootDirectory = | ||
| viteUserConfig.root ?? process.env.REMIX_ROOT ?? process.cwd(); | ||
|
|
||
| // Avoid leaking any config options that the Vite plugin doesn't support | ||
| let config = pick(options, supportedRemixConfigKeys); | ||
|
|
||
| // Only select the Remix config options that the Vite plugin uses | ||
| let { | ||
| appDirectory, | ||
|
|
@@ -385,8 +413,8 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => { | |
|
|
||
| let fingerprintedValues = { entry, routes }; | ||
| let version = getHash(JSON.stringify(fingerprintedValues), 8); | ||
| let manifestFilename = `manifest-${version}.js`; | ||
| let url = `${pluginConfig.publicPath}${manifestFilename}`; | ||
| let manifestPath = `assets/manifest-${version}.js`; | ||
| let url = `${pluginConfig.publicPath}${manifestPath}`; | ||
| let nonFingerprintedValues = { url, version }; | ||
|
|
||
| let manifest: Manifest = { | ||
|
|
@@ -395,7 +423,7 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => { | |
| }; | ||
|
|
||
| await writeFileSafe( | ||
| path.join(pluginConfig.assetsBuildDirectory, manifestFilename), | ||
| path.join(pluginConfig.assetsBuildDirectory, manifestPath), | ||
| `window.__remixManifest=${JSON.stringify(manifest)};` | ||
| ); | ||
|
|
||
|
|
@@ -516,13 +544,6 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => { | |
| base: pluginConfig.publicPath, | ||
| build: { | ||
| ...viteUserConfig.build, | ||
| // By convention Remix builds into a subdirectory within the | ||
| // public directory ("public/build" by default) so we don't want | ||
| // to copy the contents of the public directory around. This also | ||
| // ensures that we don't get caught in an infinite loop when | ||
| // `assetsBuildDirectory` is nested multiple levels deep within | ||
| // the public directory, e.g. "public/custom-base-dir/build" | ||
| copyPublicDir: false, | ||
| ...(!isSsrBuild | ||
| ? { | ||
| manifest: true, | ||
|
|
@@ -545,6 +566,7 @@ export const remixVitePlugin: RemixVitePlugin = (options = {}) => { | |
| // regardless of "ssrEmitAssets" option, so we also need to | ||
| // keep these JS files have to be kept as-is. | ||
| ssrEmitAssets: true, | ||
| copyPublicDir: false, // Assets in the public directory are only used by the client | ||
| manifest: true, // We need the manifest to detect SSR-only assets | ||
| outDir: path.dirname(pluginConfig.serverBuildPath), | ||
| rollupOptions: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,4 @@ node_modules | |
|
|
||
| /.cache | ||
| /build | ||
| /public/build | ||
| .env | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,4 @@ node_modules | |
|
|
||
| /.cache | ||
| /build | ||
| /public/build | ||
| .env | ||
Uh oh!
There was an error while loading. Please reload this page.