(opts, bundle)
| 228 | }, |
| 229 | |
| 230 | async generateBundle(opts, bundle) { |
| 231 | const { format } = opts |
| 232 | if (format !== 'es') { |
| 233 | return |
| 234 | } |
| 235 | |
| 236 | await init |
| 237 | |
| 238 | // If preload is not enabled, we parse through each imports and remove any imports to pure CSS chunks |
| 239 | // as they are removed from the bundle |
| 240 | if (!getInsertPreload(this.environment)) { |
| 241 | const removedPureCssFiles = removedPureCssFilesCache.get(config) |
| 242 | if (removedPureCssFiles && removedPureCssFiles.size > 0) { |
| 243 | for (const file in bundle) { |
| 244 | const chunk = bundle[file] |
| 245 | if (chunk.type === 'chunk' && chunk.code.includes('import')) { |
| 246 | const code = chunk.code |
| 247 | let imports!: ImportSpecifier[] |
| 248 | try { |
| 249 | imports = parseImports(code)[0].filter((i) => i.d > -1) |
| 250 | } catch (e: any) { |
| 251 | const loc = numberToPos(code, e.idx) |
| 252 | this.error({ |
| 253 | name: e.name, |
| 254 | message: e.message, |
| 255 | stack: e.stack, |
| 256 | cause: e.cause, |
| 257 | pos: e.idx, |
| 258 | loc: { ...loc, file: chunk.fileName }, |
| 259 | frame: generateCodeFrame(code, loc), |
| 260 | }) |
| 261 | } |
| 262 | |
| 263 | for (const imp of imports) { |
| 264 | const { |
| 265 | n: name, |
| 266 | s: start, |
| 267 | e: end, |
| 268 | ss: expStart, |
| 269 | se: expEnd, |
| 270 | } = imp |
| 271 | let url = name |
| 272 | if (!url) { |
| 273 | const rawUrl = code.slice(start, end) |
| 274 | if ( |
| 275 | (rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`) || |
| 276 | (rawUrl[0] === '`' && rawUrl[rawUrl.length - 1] === '`') |
| 277 | ) |
| 278 | url = rawUrl.slice(1, -1) |
| 279 | } |
| 280 | if (!url) continue |
| 281 | |
| 282 | const normalizedFile = path.posix.join( |
| 283 | path.posix.dirname(chunk.fileName), |
| 284 | url, |
| 285 | ) |
| 286 | if (removedPureCssFiles.has(normalizedFile)) { |
| 287 | // remove with Promise.resolve({}) while preserving source map location |
nothing calls this directly
no test coverage detected