(code, chunk, outputOptions)
| 83 | }, |
| 84 | |
| 85 | async renderChunk(code, chunk, outputOptions) { |
| 86 | // This plugin is included for any non-false value of config.build.minify, |
| 87 | // so that normal chunks can use the preferred minifier, and legacy chunks |
| 88 | // can use terser. |
| 89 | if ( |
| 90 | config.build.minify !== 'terser' && |
| 91 | !this.environment.config.isOutputOptionsForLegacyChunks?.(outputOptions) |
| 92 | ) { |
| 93 | return null |
| 94 | } |
| 95 | |
| 96 | // Lazy load worker. |
| 97 | worker ||= makeWorker() |
| 98 | |
| 99 | const terserPath = pathToFileURL(loadTerserPath(config.root)).href |
| 100 | try { |
| 101 | const res = await worker.run(terserPath, code, { |
| 102 | safari10: true, |
| 103 | ...terserOptions, |
| 104 | format: { |
| 105 | ...terserOptions.format, |
| 106 | // For ES lib mode, preserve comments to keep pure annotations for tree-shaking |
| 107 | preserve_annotations: |
| 108 | config.build.lib && outputOptions.format === 'es' |
| 109 | ? true |
| 110 | : terserOptions.format?.preserve_annotations, |
| 111 | }, |
| 112 | sourceMap: !!outputOptions.sourcemap, |
| 113 | module: outputOptions.format.startsWith('es'), |
| 114 | toplevel: outputOptions.format === 'cjs', |
| 115 | }) |
| 116 | return { |
| 117 | code: res.code!, |
| 118 | map: res.map as any, |
| 119 | } |
| 120 | } catch (e) { |
| 121 | if (e.line !== undefined && e.col !== undefined) { |
| 122 | e.loc = { |
| 123 | file: chunk.fileName, |
| 124 | line: e.line, |
| 125 | column: e.col, |
| 126 | } |
| 127 | } |
| 128 | if (e.pos !== undefined) { |
| 129 | e.frame = generateCodeFrame(code, e.pos) |
| 130 | } |
| 131 | throw e |
| 132 | } |
| 133 | }, |
| 134 | |
| 135 | closeBundle() { |
| 136 | worker?.stop() |
nothing calls this directly
no test coverage detected