Skip to content

Commit

Permalink
fix(taro-vite-runner): 修复 vite h5 dev & build 路径未转 posix 导致的异常 (#16124)
Browse files Browse the repository at this point in the history
Co-authored-by: William <[email protected]>
Co-authored-by: ZEJIA LIU <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2024
1 parent e0bbb17 commit 4558798
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/taro-vite-runner/src/h5/entry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'

import { fs, isEmptyObject } from '@tarojs/helper'
import { fs, isEmptyObject, normalizePath } from '@tarojs/helper'

import { getDefaultPostcssConfig } from '../postcss/postcss.h5'
import { appendVirtualModulePrefix, generateQueryString, getMode, getQueryParams } from '../utils'
Expand All @@ -14,15 +14,15 @@ export default function (viteCompilerContext: ViteH5CompilerContext): PluginOpti
const { taroConfig, app } = viteCompilerContext
const routerConfig = taroConfig.router || {}
const isProd = getMode(taroConfig) === 'production'

const configPath = normalizePath(app.configPath)
return {
name: 'taro:vite-h5-entry',
enforce: 'pre',

async resolveId (source, importer, options) {
// mpa 模式关于 入口脚本文件 的处理已经解藕到 mpa.ts
const resolved = await this.resolve(source, importer, { ...options, skipSelf: true })
if (resolved?.id && resolved.id === app.configPath) {
if (resolved?.id && resolved.id === configPath) {
const params = {
[ENTRY_QUERY]: 'true'
}
Expand Down Expand Up @@ -152,7 +152,7 @@ export default function (viteCompilerContext: ViteH5CompilerContext): PluginOpti
'import "@tarojs/components/global.css"',
'import { initPxTransform } from "@tarojs/taro"',
`import { ${routerCreator}, ${historyCreator}, ${appMountHandler} } from "@tarojs/router"`,
`import component from "${app.scriptPath}"`,
`import component from "${normalizePath(app.scriptPath)}"`,
'import { window } from "@tarojs/runtime"',
`import { ${creator} } from "${creatorLocation}"`,
importFrameworkStatement,
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-vite-runner/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import querystring from 'node:querystring'

import { isNpmPkg, recursiveMerge, REG_NODE_MODULES, resolveSync } from '@tarojs/helper'
import { isNpmPkg, normalizePath, recursiveMerge, REG_NODE_MODULES, resolveSync } from '@tarojs/helper'
import { isFunction, isString } from '@tarojs/shared'

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

0 comments on commit 4558798

Please sign in to comment.