MCPcopy
hub / github.com/vitejs/vite / loadTerserPath

Function loadTerserPath

packages/vite/src/node/plugins/terser.ts:23–36  ·  view source on GitHub ↗
(root: string)

Source from the content-addressed store, hash-verified

21
22let terserPath: string | undefined
23function loadTerserPath(root: string) {
24 if (terserPath) return terserPath
25
26 // Try resolve from project root first, then the current vite installation path
27 const resolved =
28 nodeResolveWithVite('terser', undefined, { root }) ??
29 nodeResolveWithVite('terser', _dirname, { root })
30 if (resolved) return (terserPath = resolved)
31
32 // Error if we can't find the package
33 throw new Error(
34 'terser not found. Since Vite v3, terser has become an optional dependency. You need to install it.',
35 )
36}
37
38export function terserPlugin(config: ResolvedConfig): Plugin {
39 const { maxWorkers, ...terserOptions } = config.build.terserOptions

Callers 1

renderChunkFunction · 0.85

Calls 1

nodeResolveWithViteFunction · 0.90

Tested by

no test coverage detected