Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(taro-vite-runner): 修复 vite h5 dev & build 路径未转 posix 导致的异常 #16124

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading