Skip to content

Commit 58b83f4

Browse files
authored
fix(taro-platform-h5): 修复windows开发环境Taro对象上等方法不可用 (#18153)
* fix: 修复windows开发环境Taro对象上等方法不可用 * fix:保持原有 * fix: 修复windows开发环境Taro对象上等方法不可用
1 parent 52ceb74 commit 58b83f4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,16 @@ 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+
let cleanId = id
228+
229+
if (cleanId.startsWith('\u0000')) {
230+
cleanId = cleanId.slice(1)
231+
}
232+
233+
cleanId = cleanId.split('?')[0].replace(/\\/g, '/') // 👈 替换斜杠方向
234+
235+
const normalizedSourceDir = viteCompilerContext.sourceDir.replace(/\\/g, '/') // 👈 替换斜杠方向
236+
if (cleanId.startsWith(normalizedSourceDir) && exts.some((ext) => id.includes(ext))) {
228237
// @TODO 后续考虑使用 SWC 插件的方式实现
229238
const result = await transformAsync(code, {
230239
filename: id,

0 commit comments

Comments
 (0)