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

Function handler

packages/vite/src/node/plugins/define.ts:138–165  ·  view source on GitHub ↗
(code, id)

Source from the content-addressed store, hash-verified

136
137 transform: {
138 handler(code, id) {
139 if (this.environment.config.consumer === 'client') {
140 // for dev we inject actual global defines in the vite client to
141 // avoid the transform cost. see the `clientInjection` and
142 // `importAnalysis` plugin.
143 return
144 }
145
146 if (
147 // exclude html, css and static assets for performance
148 isHTMLRequest(id) ||
149 isCSSRequest(id) ||
150 isNonJsRequest(id) ||
151 config.assetsInclude(id)
152 ) {
153 return
154 }
155
156 const [define, pattern] = getPattern(this.environment)
157 if (!pattern) return
158
159 // Check if our code needs any replacements before running esbuild
160 pattern.lastIndex = 0
161 if (!pattern.test(code)) return
162
163 const result = replaceDefine(this.environment, code, id, define)
164 return result
165 },
166 },
167 }
168}

Callers

nothing calls this directly

Calls 5

isHTMLRequestFunction · 0.90
isCSSRequestFunction · 0.90
isNonJsRequestFunction · 0.85
getPatternFunction · 0.85
replaceDefineFunction · 0.85

Tested by

no test coverage detected