@@ -6,7 +6,7 @@ import type * as Babel from "@babel/core";
66import type { NodePath , PluginObj , PluginPass } from "@babel/core" ;
77import type { Binding } from "@babel/traverse" ;
88import { basename } from "pathe" ;
9- import type { Plugin , ResolvedConfig , ViteDevServer } from "vite" ;
9+ import type { Plugin } from "vite" ;
1010
1111type State = Omit < PluginPass , "opts" > & {
1212 opts : { pick : string [ ] } ;
@@ -280,10 +280,6 @@ function treeShakeTransform({ types: t }: typeof Babel): PluginObj<State> {
280280}
281281
282282export function treeShake ( ) : Plugin {
283- let config : ResolvedConfig ;
284- const cache : Record < string , any > = { } ;
285- let server : ViteDevServer ;
286-
287283 async function transform ( id : string , code : string ) {
288284 const [ path , queryString ] = id . split ( "?" ) ;
289285 const query = new URLSearchParams ( queryString ) ;
@@ -308,46 +304,6 @@ export function treeShake(): Plugin {
308304 return {
309305 name : "tree-shake" ,
310306 enforce : "pre" ,
311- configResolved ( resolvedConfig ) {
312- config = resolvedConfig ;
313- } ,
314- configureServer ( s ) {
315- server = s ;
316- } ,
317- async handleHotUpdate ( ctx ) {
318- if ( cache [ ctx . file ] ) {
319- const mods = [ ] ;
320- const newCode = await ctx . read ( ) ;
321- for ( const [ id , code ] of Object . entries ( cache [ ctx . file ] ) ) {
322- const transformed = await transform ( id , newCode ) ;
323- if ( ! transformed ) continue ;
324-
325- const { code : transformedCode } = transformed ;
326-
327- if ( transformedCode !== code ) {
328- const mod = server . moduleGraph . getModuleById ( id ) ;
329- if ( mod ) mods . push ( mod ) ;
330- }
331-
332- cache [ ctx . file ] ??= { } ;
333- cache [ ctx . file ] [ id ] = transformedCode ;
334- // server.moduleGraph.setModuleSource(id, code);
335- }
336-
337- return mods ;
338- }
339- // const mods = [];
340- // [...server.moduleGraph.urlToModuleMap.entries()].forEach(([url, m]) => {
341- // if (m.file === ctx.file && m.id.includes("pick=")) {
342- // if (!m.id.includes("pick=loader")) {
343- // mods.push(m);
344- // }
345- // }
346- // });
347- // return mods;
348- // // this.router.updateRoute(ctx.path);
349- // }
350- } ,
351307 async transform ( code , id ) {
352308 const [ path , queryString ] = id . split ( "?" ) ;
353309 if ( ! path ) return ;
@@ -358,9 +314,6 @@ export function treeShake(): Plugin {
358314 const transformed = await transform ( id , code ) ;
359315 if ( ! transformed ?. code ) return ;
360316
361- cache [ path ] ??= { } ;
362- cache [ path ] [ id ] = transformed . code ;
363-
364317 return {
365318 code : transformed . code ,
366319 map : transformed . map ,
0 commit comments