()
| 9 | import { withTrailingSlash } from '../../shared/utils' |
| 10 | |
| 11 | export function prepareOutDirPlugin(): Plugin { |
| 12 | const rendered = new Set<Environment>() |
| 13 | return { |
| 14 | name: 'vite:prepare-out-dir', |
| 15 | watchChange() { |
| 16 | rendered.delete(this.environment) |
| 17 | }, |
| 18 | renderStart: { |
| 19 | order: 'pre', |
| 20 | handler() { |
| 21 | if (rendered.has(this.environment)) { |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | const { config } = this.environment |
| 26 | if (config.build.write) { |
| 27 | rendered.add(this.environment) |
| 28 | const { root, build: options } = config |
| 29 | const resolvedOutDirs = getResolvedOutDirs( |
| 30 | root, |
| 31 | options.outDir, |
| 32 | options.rolldownOptions.output, |
| 33 | ) |
| 34 | const emptyOutDir = resolveEmptyOutDir( |
| 35 | options.emptyOutDir, |
| 36 | root, |
| 37 | resolvedOutDirs, |
| 38 | this.environment.logger, |
| 39 | ) |
| 40 | prepareOutDir(resolvedOutDirs, emptyOutDir, this.environment) |
| 41 | } |
| 42 | }, |
| 43 | }, |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | function prepareOutDir( |
| 48 | outDirs: Set<string>, |
no outgoing calls
no test coverage detected