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

Function makeWorker

packages/vite/src/node/plugins/terser.ts:41–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39 const { maxWorkers, ...terserOptions } = config.build.terserOptions
40
41 const makeWorker = () =>
42 new WorkerWithFallback(
43 () =>
44 async (
45 terserPath: string,
46 code: string,
47 options: TerserMinifyOptions,
48 ) => {
49 const terser: typeof import('terser') = await import(terserPath)
50 try {
51 return (await terser.minify(code, options)) as TerserMinifyOutput
52 } catch (e) {
53 // convert to a plain object as additional properties of Error instances are not
54 // sent back to the main thread
55 throw { stack: e.stack /* stack is non-enumerable */, ...e }
56 }
57 },
58 {
59 shouldUseFake(_terserPath, _code, options) {
60 return !!(
61 (typeof options.mangle === 'object' &&
62 (options.mangle.nth_identifier?.get ||
63 (typeof options.mangle.properties === 'object' &&
64 options.mangle.properties.nth_identifier?.get))) ||
65 typeof options.format?.comments === 'function' ||
66 typeof options.output?.comments === 'function' ||
67 options.nameCache
68 )
69 },
70 max: maxWorkers,
71 },
72 )
73
74 let worker: ReturnType<typeof makeWorker>
75

Callers 1

renderChunkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected