Skip to content

Commit 4558798

Browse files
weizsWilliamZEJIA-LIU
authored
fix(taro-vite-runner): 修复 vite h5 dev & build 路径未转 posix 导致的异常 (#16124)
Co-authored-by: William <[email protected]> Co-authored-by: ZEJIA LIU <[email protected]>
1 parent e0bbb17 commit 4558798

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/taro-vite-runner/src/h5/entry.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path'
22

3-
import { fs, isEmptyObject } from '@tarojs/helper'
3+
import { fs, isEmptyObject, normalizePath } from '@tarojs/helper'
44

55
import { getDefaultPostcssConfig } from '../postcss/postcss.h5'
66
import { appendVirtualModulePrefix, generateQueryString, getMode, getQueryParams } from '../utils'
@@ -14,15 +14,15 @@ export default function (viteCompilerContext: ViteH5CompilerContext): PluginOpti
1414
const { taroConfig, app } = viteCompilerContext
1515
const routerConfig = taroConfig.router || {}
1616
const isProd = getMode(taroConfig) === 'production'
17-
17+
const configPath = normalizePath(app.configPath)
1818
return {
1919
name: 'taro:vite-h5-entry',
2020
enforce: 'pre',
2121

2222
async resolveId (source, importer, options) {
2323
// mpa 模式关于 入口脚本文件 的处理已经解藕到 mpa.ts
2424
const resolved = await this.resolve(source, importer, { ...options, skipSelf: true })
25-
if (resolved?.id && resolved.id === app.configPath) {
25+
if (resolved?.id && resolved.id === configPath) {
2626
const params = {
2727
[ENTRY_QUERY]: 'true'
2828
}
@@ -152,7 +152,7 @@ export default function (viteCompilerContext: ViteH5CompilerContext): PluginOpti
152152
'import "@tarojs/components/global.css"',
153153
'import { initPxTransform } from "@tarojs/taro"',
154154
`import { ${routerCreator}, ${historyCreator}, ${appMountHandler} } from "@tarojs/router"`,
155-
`import component from "${app.scriptPath}"`,
155+
`import component from "${normalizePath(app.scriptPath)}"`,
156156
'import { window } from "@tarojs/runtime"',
157157
`import { ${creator} } from "${creatorLocation}"`,
158158
importFrameworkStatement,

packages/taro-vite-runner/src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path'
22
import querystring from 'node:querystring'
33

4-
import { isNpmPkg, recursiveMerge, REG_NODE_MODULES, resolveSync } from '@tarojs/helper'
4+
import { isNpmPkg, normalizePath, recursiveMerge, REG_NODE_MODULES, resolveSync } from '@tarojs/helper'
55
import { isFunction, isString } from '@tarojs/shared'
66

77
import { backSlashRegEx, MINI_EXCLUDE_POSTCSS_PLUGIN_NAME, needsEscapeRegEx, quoteNewlineRegEx } from './constants'
@@ -118,7 +118,7 @@ export function genRouterResource (page: VitePageMeta) {
118118
'Object.assign({',
119119
` path: '${page.name}',`,
120120
' load: async function(context, params) {',
121-
` const page = await import("${page.scriptPath}")`,
121+
` const page = await import("${normalizePath(page.scriptPath)}")`,
122122
' return [page, context, params]',
123123
' }',
124124
`}, ${JSON.stringify(page.config)})`

0 commit comments

Comments
 (0)