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

Function replaceDefine

packages/vite/src/node/plugins/define.ts:170–198  ·  view source on GitHub ↗
(
  environment: Environment,
  code: string,
  id: string,
  define: Record<string, string>,
)

Source from the content-addressed store, hash-verified

168}
169
170export function replaceDefine(
171 environment: Environment,
172 code: string,
173 id: string,
174 define: Record<string, string>,
175): {
176 code: string
177 map: ReturnType<typeof transformSync>['map'] | null
178} {
179 const result = transformSync(id, code, {
180 lang: 'js',
181 sourceType: 'module',
182 define,
183 sourcemap:
184 environment.config.command === 'build'
185 ? !!environment.config.build.sourcemap
186 : true,
187 tsconfig: false,
188 })
189
190 if (result.errors.length > 0) {
191 throw new AggregateError(result.errors, 'oxc transform error')
192 }
193
194 return {
195 code: result.code,
196 map: result.map || null,
197 }
198}
199
200/**
201 * Like `JSON.stringify` but keeps raw string values as a literal

Callers 2

transformFunction · 0.90
handlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected