Skip to content

Commit d489557

Browse files
committed
chore: refactor runtime code
1 parent 11065c3 commit d489557

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

packages/core/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ const unplugin = createUnplugin<Options>(
130130
this.error(`[${NAME}] ${err}`)
131131
}
132132
},
133+
buildEnd() {
134+
if (context.isServer) {
135+
if (context.framework === 'vite'
136+
|| context.framework === 'rollup'
137+
|| context.framework === 'esbuild')
138+
context.isHMR = false
139+
}
140+
},
133141
},
134142
]
135143
})

packages/core/runtime/handle-inject-css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { injectCSSVars } from '../inject'
33
import type { MagicStringBase } from 'magic-string-ast'
44
import type { IVueCSSVarsCtx } from '../types'
55

6+
// TODO: unit test
67
export function handleInjectCss(
78
id: string,
89
code: string,
@@ -18,6 +19,5 @@ export function handleInjectCss(
1819
)
1920
mgcStr = injectRes.mgcStr
2021
injectRes.vbindVariableList && ctx.vbindVariableList.set(id, injectRes.vbindVariableList)
21-
// TODO vite hmr close ? isHMR -> false
2222
return mgcStr
2323
}

packages/core/runtime/handle-variable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getVariable, matchVariable } from '../parser'
44
import { getVBindVariableListByPath } from './process-css'
55
import type { IVueCSSVarsCtx } from '../types'
66

7+
// TODO: unit test
78
export function handleVBindVariable(
89
code: string,
910
id: string,

packages/core/runtime/vite.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { IVueCSSVarsCtx } from '../types'
77
import type { MagicStringBase } from 'magic-string-ast'
88
import type { HmrContext, ResolvedConfig } from 'vite'
99

10+
// TODO: unit test
1011
export function transformPreVite(
1112
id: string,
1213
code: string,
@@ -30,6 +31,7 @@ export function transformPreVite(
3031
return mgcStr
3132
}
3233

34+
// TODO: unit test
3335
export function transformPostVite(
3436
id: string,
3537
code: string,
@@ -50,6 +52,7 @@ export function transformPostVite(
5052
return mgcStr
5153
}
5254

55+
// TODO: unit test
5356
export const vitePlugin = (ctx: IVueCSSVarsCtx) => {
5457
return {
5558
// Vite plugin

packages/core/runtime/webpack.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { handleInjectCss } from './handle-inject-css'
66
import type { IVueCSSVarsCtx } from '../types'
77
import type { MagicStringBase } from 'magic-string-ast'
88

9+
// TODO: unit test
910
export function transformPreWebpack(
1011
id: string,
1112
code: string,
@@ -21,6 +22,7 @@ export function transformPreWebpack(
2122
}
2223
}
2324

25+
// TODO: unit test
2426
export function transformPostWebpack(
2527
id: string,
2628
code: string,
@@ -45,6 +47,7 @@ export function transformPostWebpack(
4547
return mgcStr
4648
}
4749

50+
// TODO: unit test
4851
export const webpackPlugin = (ctx: IVueCSSVarsCtx, compiler: any) => {
4952
// mark webpack hmr
5053
let modifiedFile = ''

0 commit comments

Comments
 (0)