Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
19 changes: 19 additions & 0 deletions docs/config/dep-optimization-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ Certain options are omitted since changing them would not be compatible with Vit

Set to `true` to force dependency pre-bundling, ignoring previously cached optimized dependencies.

## optimizeDeps.lockFilePath <NonInheritBadge />

- **Experimental**
- **Type:** `string`

Path to a custom lockfile to use for dependency optimization hash calculation. When specified, Vite will use this lockfile instead of searching for standard lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml, etc.).

This is useful for monorepo tools like Rush.js that place lockfiles in non-standard locations such as `.rush/temp/shrinkwrap-deps.json`.

```js twoslash
import { defineConfig } from 'vite'
// ---cut---
export default defineConfig({
optimizeDeps: {
lockFilePath: '.rush/temp/shrinkwrap-deps.json',
},
})
```

## optimizeDeps.noDiscovery <NonInheritBadge />

- **Type:** `boolean`
Expand Down
32 changes: 31 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export interface DepOptimizationConfig {
* @experimental
*/
needsInterop?: string[]
/**
* Path to a custom lockfile to use for dependency optimization hash calculation.
* When specified, Vite will use this lockfile instead of searching for standard
* lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml, etc.).
* This is useful for monorepo tools like Rush.js that place lockfiles in
* non-standard locations.
* @experimental
*/
lockFilePath?: string
/**
* Options to pass to esbuild during the dep scanning and optimization
*
Expand Down Expand Up @@ -1249,6 +1258,12 @@ const lockfileFormats = [
checkPatchesDir: 'patches',
manager: 'bun',
},
{
path: '.rush/temp/shrinkwrap-deps.json',
// Included in lockfile
checkPatchesDir: false,
manager: 'pnpm',
},
].sort((_, { manager }) => {
return process.env.npm_config_user_agent?.startsWith(manager) ? 1 : -1
})
Expand Down Expand Up @@ -1292,7 +1307,22 @@ function getConfigHash(environment: Environment): string {
}

function getLockfileHash(environment: Environment): string {
const lockfilePath = lookupFile(environment.config.root, lockfilePaths)
const { config } = environment
const customLockFilePath = config.optimizeDeps.lockFilePath

let lockfilePath: string | undefined

if (customLockFilePath) {
// Use custom lockfile path if specified
const fullCustomPath = path.resolve(config.root, customLockFilePath)
lockfilePath = tryStatSync(fullCustomPath)?.isFile()
? fullCustomPath
: undefined
} else {
// Use standard lockfile detection
lockfilePath = lookupFile(config.root, lockfilePaths)
}

let content = lockfilePath ? fs.readFileSync(lockfilePath, 'utf-8') : ''
if (lockfilePath) {
const normalizedLockfilePath = lockfilePath.replaceAll('\\', '/')
Expand Down