Skip to content

Commit 30e5a48

Browse files
committed
fix(taro-platform-h5): 修复windows开发环境Taro对象上等方法不可用
1 parent 3195665 commit 30e5a48

File tree

2 files changed

+213
-616
lines changed

2 files changed

+213
-616
lines changed

packages/taro-platform-h5/src/program.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,17 @@ export default class H5 extends TaroPlatformWeb {
224224
const viteCompilerContext = await getViteH5CompilerContext(this)
225225
if (viteCompilerContext) {
226226
const exts = Array.from(new Set(viteCompilerContext.frameworkExts.concat(SCRIPT_EXT)))
227-
if (id.startsWith(viteCompilerContext.sourceDir) && exts.some((ext) => id.includes(ext))) {
227+
228+
let cleanId = id
229+
230+
if (cleanId.startsWith('\u0000')) {
231+
cleanId = cleanId.slice(1)
232+
}
233+
234+
cleanId = cleanId.split('?')[0].replace(/\\/g, '/') // 👈 替换斜杠方向
235+
236+
const normalizedSourceDir = viteCompilerContext.sourceDir.replace(/\\/g, '/') // 👈 替换斜杠方向
237+
if (cleanId.startsWith(normalizedSourceDir) && exts.some((ext) => id.includes(ext))) {
228238
// @TODO 后续考虑使用 SWC 插件的方式实现
229239
const result = await transformAsync(code, {
230240
filename: id,

0 commit comments

Comments
 (0)