* Build an App environment, or a App library (if libraryOptions is provided)
( environment: BuildEnvironment, )
| 811 | * Build an App environment, or a App library (if libraryOptions is provided) |
| 812 | **/ |
| 813 | async function buildEnvironment( |
| 814 | environment: BuildEnvironment, |
| 815 | ): Promise<RolldownOutput | RolldownOutput[] | RolldownWatcher> { |
| 816 | const { logger, config } = environment |
| 817 | const { root, build: options } = config |
| 818 | |
| 819 | logger.info( |
| 820 | colors.cyan( |
| 821 | `vite v${VERSION} ${colors.green( |
| 822 | `building ${environment.name} environment for ${environment.config.mode}...`, |
| 823 | )}`, |
| 824 | ), |
| 825 | ) |
| 826 | |
| 827 | let bundle: RolldownBuild | undefined |
| 828 | let startTime: number | undefined |
| 829 | try { |
| 830 | const chunkMetadataMap = new ChunkMetadataMap() |
| 831 | const rolldownOptions = resolveRolldownOptions( |
| 832 | environment, |
| 833 | chunkMetadataMap, |
| 834 | ) |
| 835 | |
| 836 | // watch file changes with rollup |
| 837 | if (options.watch) { |
| 838 | logger.info(colors.cyan(`\nwatching for file changes...`)) |
| 839 | |
| 840 | const resolvedOutDirs = getResolvedOutDirs( |
| 841 | root, |
| 842 | options.outDir, |
| 843 | options.rolldownOptions.output, |
| 844 | ) |
| 845 | const emptyOutDir = resolveEmptyOutDir( |
| 846 | options.emptyOutDir, |
| 847 | root, |
| 848 | resolvedOutDirs, |
| 849 | logger, |
| 850 | ) |
| 851 | const resolvedChokidarOptions = resolveChokidarOptions( |
| 852 | { |
| 853 | // @ts-expect-error chokidar option does not exist in rolldown but used for backward compat |
| 854 | ...(rolldownOptions.watch || {}).chokidar, |
| 855 | // @ts-expect-error chokidar option does not exist in rolldown but used for backward compat |
| 856 | ...options.watch.chokidar, |
| 857 | }, |
| 858 | resolvedOutDirs, |
| 859 | emptyOutDir, |
| 860 | environment.config.cacheDir, |
| 861 | ) |
| 862 | |
| 863 | const { watch } = await import('rolldown') |
| 864 | const watcher = watch({ |
| 865 | ...rolldownOptions, |
| 866 | watch: { |
| 867 | ...rolldownOptions.watch, |
| 868 | ...options.watch, |
| 869 | watcher: convertToWatcherOptions(resolvedChokidarOptions), |
| 870 | }, |
no test coverage detected