(root: string)
| 21 | |
| 22 | let terserPath: string | undefined |
| 23 | function 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 | |
| 38 | export function terserPlugin(config: ResolvedConfig): Plugin { |
| 39 | const { maxWorkers, ...terserOptions } = config.build.terserOptions |
no test coverage detected