Skip to content

Commit

Permalink
feat: add ssr.resolve.mainFields option (#18646)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 13, 2024
1 parent 0e1f437 commit a6f5f5b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/config/ssr-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ When using this option, make sure to run Node with [`--conditions` flag](https:/
For example, when setting `['node', 'custom']`, you should run `NODE_OPTIONS='--conditions custom' vite` in dev and `NODE_OPTIONS="--conditions custom" node ./dist/server.js` after build.

:::

### ssr.resolve.mainFields

- **Type:** `string[]`
- **Default:** `['module', 'jsnext:main', 'jsnext']`

List of fields in `package.json` to try when resolving a package's entry point. Note this takes lower precedence than conditional exports resolved from the `exports` field: if an entry point is successfully resolved from `exports`, the main field will be ignored. This setting only affect non-externalized dependencies.
2 changes: 2 additions & 0 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ There are other breaking changes which only affect few users.
- If you are specifying a CommonJS file as an entry point, you may need additional steps. Read [the commonjs plugin documentation](https://github.com/rollup/plugins/blob/master/packages/commonjs/README.md#using-commonjs-files-as-entry-points) for more details.
- [[#18243] chore(deps)!: migrate `fast-glob` to `tinyglobby`](https://github.com/vitejs/vite/pull/18243)
- Range braces (`{01..03}``['01', '02', '03']`) and incremental braces (`{2..8..2}``['2', '4', '6', '8']`) are no longer supported in globs.
- [[#18395] feat(resolve)!: allow removing conditions](https://github.com/vitejs/vite/pull/18395)
- This PR not only introduces a breaking change mentioned above as "Default value for `resolve.conditions`", but also makes `resolve.mainFields` to not be used for no-externalized dependencies in SSR. If you were using `resolve.mainFields` and want to apply that to no-externalized dependencies in SSR, you can use [`ssr.resolve.mainFields`](/config/ssr-options#ssr-resolve-mainfields).
- [[#18493] refactor!: remove fs.cachedChecks option](https://github.com/vitejs/vite/pull/18493)
- This opt-in optimization was removed due to edge cases when writing a file in a cached folder and immediately importing it.

Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ export async function resolveConfig(
configEnvironmentsSsr.resolve.conditions ??= config.ssr?.resolve?.conditions
configEnvironmentsSsr.resolve.externalConditions ??=
config.ssr?.resolve?.externalConditions
configEnvironmentsSsr.resolve.mainFields ??= config.ssr?.resolve?.mainFields
configEnvironmentsSsr.resolve.external ??= config.ssr?.external
configEnvironmentsSsr.resolve.noExternal ??= config.ssr?.noExternal
}
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/node/ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface SSROptions {
* @default []
*/
externalConditions?: string[]

mainFields?: string[]
}
}

Expand Down

0 comments on commit a6f5f5b

Please sign in to comment.