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(mini): 修复 webpack4 中 wxml 和 wxs 的 loader 路径问题 #14427

Merged
merged 5 commits into from
Sep 4, 2023

Conversation

xuanzebin
Copy link
Member

这个 PR 做了什么? (简要描述所做更改)

  • 修复 webpack4 中 wxml 和 wxs 的 loader 路径问题

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

  • 所有小程序
  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 字节跳动小程序
  • QQ 轻应用
  • 京东小程序
  • 快应用平台(QuickApp)
  • Web 平台(H5)
  • 移动端(React-Native)
  • 鸿蒙(harmony)

@xuanzebin xuanzebin added this to the 3.6.15 milestone Aug 28, 2023
@xuanzebin xuanzebin requested a review from Chen-jj August 28, 2023 03:29
// 因此在 webpack4 中如果包含 sourceDir,证明是在 src 内的路径
if (resourcePath.includes(sourceDir)) {
// 直接将 /xxx/src/yyy/zzz.wxml 转换成 yyy/zzz.wxml 即可
return resourcePath.replace(sourceDir + '/', '').replace(/node_modules/gi, 'npm')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的路径拼接是否要兼容下 windows? 我看原代码是 path.join 处理过

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,晚点我兼容一下

@ZakaryCode ZakaryCode modified the milestones: 3.6.15, 3.6.16 Aug 30, 2023
@peggyannie
Copy link

环境:Taro 3.6.15 , React , 微信基础库3.0.1
问题:原生wxml页面内容被吞
复现:
index.wxml

<view style="text-align: center;">页面Test</view>

Taro编译后:

<!--wxmlTest/index.wxml-->
<text>wxmlTest/index.wxml</text>

@yetta
Copy link

yetta commented Aug 31, 2023

这个问题什么时候可以合并到 release 主分支来使用?急用

@xuanzebin xuanzebin merged commit 78a16c4 into next Sep 4, 2023
3 of 4 checks passed
@xuanzebin xuanzebin deleted the fix/source_path branch September 4, 2023 07:41
@yetta
Copy link

yetta commented Sep 11, 2023

taro 升级到 3.6.16 版本后,编译原生组件依然有问题,报错信息如下
VM85:17 WXMLRT_$7061636b616765476f6f64615061795375622f:./base.wxml:template:375:20: Template tmpl_3_10 not found.

原生组件编译结果 AdCustom/index.wxml
<ad-custom unit-id="{{unitId}}" bindload="adLoad" binderror="adError"></ad-custom>

@@ -92,7 +92,7 @@ export class MiniWebpackModule {
generator: {
filename ({ filename }) {
const extname = path.extname(filename)
return filename.replace(sourceRoot + '/', '').replace(extname, fileType.templ).replace(/node_modules/gi, 'npm')
return filename.replace(sourceRoot + path.sep, '').replace(extname, fileType.templ).replace(/node_modules/gi, 'npm')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigmeow @xuanzebin 这个兼容有问题,升级到3.6.16后,在Windows系统构建时,混合引入的原生组件在dist中放置的位置都有问题。

下面是在Windows下输出,filename是unix格式的路径,path.sep却是Windows专用的分隔符, filename的路径替换失效了

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以它本来是兼容的,特意兼容的 windows 结果反倒不兼容了?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigmeow 是的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能得麻烦你分别在 cmdpowershell 下都跑下代码,确认下是否都是这个问题

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigmeow 我都试过了,效果是一样的。Debug看了下,webpack内部会把这里的filename转换成posix路径。

image

@bigmeow
Copy link
Member

bigmeow commented Sep 14, 2023

mark
#14544

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

原生组件都不能引用了,报路径错误
7 participants