From 47a41501095ac6b97b37eb7b049cff7dcb21bac8 Mon Sep 17 00:00:00 2001 From: yoho Date: Tue, 19 Apr 2022 20:12:42 +0800 Subject: [PATCH] fix: useless chunk cache --- packages/vite/src/node/plugins/worker.ts | 28 ++---------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index 49fe6b494af899..0b5908551c6d87 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -6,13 +6,9 @@ import type Rollup from 'rollup' import { ENV_PUBLIC_PATH } from '../constants' import path from 'path' import { onRollupWarning } from '../build' -import type { TransformPluginContext, EmittedAsset } from 'rollup' +import type { TransformPluginContext } from 'rollup' interface WorkerCache { - // let the worker chunks all emit in the top-level emitFile - // - chunks: Map - // worker bundle don't deps on any more worker runtime info an id only had an result. // save worker bundled file id to avoid repeated execution of bundles // @@ -22,18 +18,6 @@ interface WorkerCache { const WorkerFileId = 'worker_file' const workerCache = new WeakMap() -function emitWorkerChunks(config: ResolvedConfig, asset: EmittedAsset): string { - const fileName = asset.fileName! - const workerMap = workerCache.get(config.rawConfig || config)! - if (workerMap.chunks.has(fileName)) { - return (workerMap.chunks.get(fileName)! as any).hash - } - const hash = getAssetHash(fileName) - ;(asset as any).hash = hash - workerMap.chunks.set(fileName, asset) - return hash -} - // Nested worker construction is a recursive process. The outputChunk of asset type can be output directly. // But the outputChunk of the chunk type needs to use the asset type to emitFile, // which will cause it to become an asset in the recursive process. @@ -89,20 +73,13 @@ export async function bundleWorkerEntry( if (outputChunk.type === 'asset') { ctx.emitFile(outputChunk) } else if (outputChunk.type === 'chunk') { - emitWorkerChunks(config, { + ctx.emitFile({ fileName: outputChunk.fileName, source: outputChunk.code, type: 'asset' }) } }) - if (!config.isWorker) { - const workerMap = workerCache.get(config.rawConfig || config)! - workerMap.chunks.forEach((asset) => { - ctx.emitFile(asset) - }) - workerMap.chunks.clear() - } } finally { await bundle.close() } @@ -193,7 +170,6 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin { return } workerCache.set(config, { - chunks: new Map(), bundle: new Map() }) },