(opts, bundle)
| 277 | }, |
| 278 | |
| 279 | async generateBundle(opts, bundle) { |
| 280 | const { format } = opts |
| 281 | if (format !== 'es') { |
| 282 | return |
| 283 | } |
| 284 | |
| 285 | await init |
| 286 | |
| 287 | // If preload is not enabled, we parse through each imports and remove any imports to pure CSS chunks |
| 288 | // as they are removed from the bundle |
| 289 | if (!getInsertPreload(this.environment)) { |
| 290 | const removedPureCssFiles = removedPureCssFilesCache.get(config) |
| 291 | if (removedPureCssFiles && removedPureCssFiles.size > 0) { |
| 292 | for (const file in bundle) { |
| 293 | const chunk = bundle[file] |
| 294 | if (chunk.type === 'chunk' && chunk.code.includes('import')) { |
| 295 | const code = chunk.code |
| 296 | let imports!: ImportSpecifier[] |
| 297 | try { |
| 298 | imports = parseImports(code)[0].filter((i) => i.d > -1) |
| 299 | } catch (e: any) { |
| 300 | const loc = numberToPos(code, e.idx) |
| 301 | this.error({ |
| 302 | name: e.name, |
| 303 | message: e.message, |
| 304 | stack: e.stack, |
| 305 | cause: e.cause, |
| 306 | pos: e.idx, |
| 307 | loc: { ...loc, file: chunk.fileName }, |
| 308 | frame: generateCodeFrame(code, loc), |
| 309 | }) |
| 310 | } |
| 311 | |
| 312 | for (const imp of imports) { |
| 313 | const { |
| 314 | n: name, |
| 315 | s: start, |
| 316 | e: end, |
| 317 | ss: expStart, |
| 318 | se: expEnd, |
| 319 | } = imp |
| 320 | let url = name |
| 321 | if (!url) { |
| 322 | const rawUrl = code.slice(start, end) |
| 323 | if ( |
| 324 | (rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`) || |
| 325 | (rawUrl[0] === '`' && rawUrl[rawUrl.length - 1] === '`') |
| 326 | ) |
| 327 | url = rawUrl.slice(1, -1) |
| 328 | } |
| 329 | if (!url) continue |
| 330 | |
| 331 | const normalizedFile = path.posix.join( |
| 332 | path.posix.dirname(chunk.fileName), |
| 333 | url, |
| 334 | ) |
| 335 | if (removedPureCssFiles.has(normalizedFile)) { |
| 336 | // remove with Promise.resolve({}) while preserving source map location |
nothing calls this directly
no test coverage detected