Skip to content

Commit 05b17df

Browse files
authoredJul 9, 2022
docs: update api-javascript (#8999)
1 parent 2a9bc6d commit 05b17df

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed
 

‎docs/guide/api-javascript.md

+91-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ The `InlineConfig` interface extends `UserConfig` with additional properties:
4444
- `configFile`: specify config file to use. If not set, Vite will try to automatically resolve one from project root. Set to `false` to disable auto resolving.
4545
- `envFile`: Set to `false` to disable `.env` files.
4646

47+
## `ResolvedConfig`
48+
49+
The `ResolvedConfig` interface has all the same properties of a `UserConfig`, except most properties are resolved and non-undefined. It also contains utilities like:
50+
51+
- `config.assetsInclude`: A function to check if an `id` is considered an asset.
52+
- `config.logger`: Vite's internal logger object.
53+
4754
## `ViteDevServer`
4855

4956
```ts
@@ -189,12 +196,74 @@ import { preview } from 'vite'
189196
async function resolveConfig(
190197
inlineConfig: InlineConfig,
191198
command: 'build' | 'serve',
192-
defaultMode?: string
199+
defaultMode = 'development'
193200
): Promise<ResolvedConfig>
194201
```
195202

196203
The `command` value is `serve` in dev (in the cli `vite`, `vite dev`, and `vite serve` are aliases).
197204

205+
## `mergeConfig`
206+
207+
**Type Signature:**
208+
209+
```ts
210+
function mergeConfig(
211+
defaults: Record<string, any>,
212+
overrides: Record<string, any>,
213+
isRoot = true
214+
): Record<string, any>
215+
```
216+
217+
Deeply merge two Vite configs. `isRoot` represents the level within the Vite config which is being merged. For example, set `false` if you're merging two `build` options.
218+
219+
## `searchForWorkspaceRoot`
220+
221+
**Type Signature:**
222+
223+
```ts
224+
function searchForWorkspaceRoot(
225+
current: string,
226+
root = searchForPackageRoot(current)
227+
): string
228+
```
229+
230+
**Related:** [server.fs.allow](/config/server-options.md#server-fs-allow)
231+
232+
Search for the root of the potential workspace if it meets the following conditions, otherwise it would fallback to `root`:
233+
234+
- contains `workspaces` field in `package.json`
235+
- contains one of the following file
236+
- `lerna.json`
237+
- `pnpm-workspace.yaml`
238+
239+
## `loadEnv`
240+
241+
**Type Signature:**
242+
243+
```ts
244+
function loadEnv(
245+
mode: string,
246+
envDir: string,
247+
prefixes: string | string[] = 'VITE_'
248+
): Record<string, string>
249+
```
250+
251+
**Related:** [`.env` Files](./env-and-mode.md#env-files)
252+
253+
Load `.env` files within the `envDir`. By default only env variables prefixed with `VITE_` are loaded, unless `prefixes` is changed.
254+
255+
## `normalizePath`
256+
257+
**Type Signature:**
258+
259+
```ts
260+
function normalizePath(id: string): string
261+
```
262+
263+
**Related:** [Path Normalization](./api-plugin.md#path-normalization)
264+
265+
Normalizes a path to interoperate between Vite plugins.
266+
198267
## `transformWithEsbuild`
199268

200269
**Type Signature:**
@@ -207,3 +276,24 @@ async function transformWithEsbuild(
207276
inMap?: object
208277
): Promise<ESBuildTransformResult>
209278
```
279+
280+
Transform JavaScript or TypeScript with esbuild. Useful for plugins that prefers matching Vite's internal esbuild transform.
281+
282+
## `loadConfigFromFile`
283+
284+
**Type Signature:**
285+
286+
```ts
287+
async function loadConfigFromFile(
288+
configEnv: ConfigEnv,
289+
configFile?: string,
290+
configRoot: string = process.cwd(),
291+
logLevel?: LogLevel
292+
): Promise<{
293+
path: string
294+
config: UserConfig
295+
dependencies: string[]
296+
} | null>
297+
```
298+
299+
Load a Vite config file manually with esbuild.

‎packages/vite/src/node/optimizer/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ export interface DepOptimizationMetadata {
214214
}
215215

216216
/**
217-
* Used by Vite CLI when running `vite optimize`
217+
* Scan and optimize dependencies within a project.
218+
* Used by Vite CLI when running `vite optimize`.
218219
*/
219220
export async function optimizeDeps(
220221
config: ResolvedConfig,

0 commit comments

Comments
 (0)
Please sign in to comment.