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

Function serializeDefine

packages/vite/src/node/plugins/define.ts:205–217  ·  view source on GitHub ↗
(define: Record<string, any>)

Source from the content-addressed store, hash-verified

203 * the global `window` object directly.
204 */
205export function serializeDefine(define: Record<string, any>): string {
206 let res = `{`
207 const keys = Object.keys(define).sort()
208 for (let i = 0; i < keys.length; i++) {
209 const key = keys[i]
210 const val = define[key]
211 res += `${JSON.stringify(key)}: ${handleDefineValue(val)}`
212 if (i !== keys.length - 1) {
213 res += `, `
214 }
215 }
216 return res + `}`
217}
218
219function handleDefineValue(value: any): string {
220 if (typeof value === 'undefined') return 'undefined'

Callers 3

getEnvFunction · 0.90
clientInjectionsPluginFunction · 0.90
generatePatternFunction · 0.85

Calls 1

handleDefineValueFunction · 0.85

Tested by

no test coverage detected