uni-app3 uniRuntimeHooksPlugin导致sourcemap错误,
- Dominant language
- JavaScript
- Stars
- 41.6k
- Forks
- 3.7k
- Avg merge
- 7h 6m
- Merged PRs (30d)
- 6
Description
**问题描述**
uniRuntimeHooksPlugin插件对代码进行了转换,却返回了`map: { mappings: '' }`,导致所有带有`onPageScroll` `onShareAppMessage` `onShareTimeline` 的页面生产的sourcemap都是错误的。
**复现步骤**
对于页面
```vue
console.log(1111);
```
生成的sourcemap为
```json
{"version":3,"file":"index.js","sources":["../../../../../src/pages/index/index.vue","../../../../../uniPage:/cGFnZXMvaW5kZXgvaW5kZXgudnVl"],"sourcesContent":["\r\n \r\n\r\n\r\nconsole.log(1111);\r\n\r\n","import MiniProgramPage from 'D:/gitlab/my-vue3-project/src/pages/index/index.vue'\nwx.createPage(MiniProgramPage)"],"names":["console","log","wx","createPage","MiniProgramPage"],"mappings":"iGAIAA,QAAQC,IAAI,qBCHZC,GAAGC,WAAWC"}
```
加上`onPageScroll`
```vue
console.log('onPageScroll');
```
生成的sourcemap为
```json
{"version":3,"file":"index.js","sources":["../../../../../uniPage:/cGFnZXMvaW5kZXgvaW5kZXgudnVl"],"sourcesContent":["import MiniProgramPage from 'D:/gitlab/my-vue3-project/src/pages/index/index.vue'\nwx.createPage(MiniProgramPage)"],"names":["wx","createPage","MiniProgramPage"],"mappings":"+JACAA,GAAGC,WAAWC"}
```
**预期结果**
生产正确的sourcemap
**实际结果**
sourcemap错误,丢失了源文件的映射
**系统信息:**
- 发行平台: 微信小程序
- 操作系统 windows10
- uni-app版本 3.0.0-alpha-3080420230602001
**补充信息**
https://github.com/dcloudio/uni-app/blob/4cfe9d7d19f067599a287f00dfdc44c2ac41fc59/packages/uni-mp-vite/src/plugins/runtimeHooks.ts#L42-L52
根据rollup的文档,仅在sourcemap无意义时才返回`map: { mappings: '' }`,这里做了代码转换,显然是有意义的。
这里用了compiler-sfc的rewriteDefault的方法,返回的是字符串而非magic-string,看起来需要将vue的版本升级到 3.3.4,使用rewriteDefaultAST方法
https://github.com/vuejs/core/blob/0e8bbe873e579f3d3a74c44af28f7df9e7a06978/packages/compiler-sfc/src/rewriteDefault.ts#L11-L17
Contributor guide
Assessment
This issue has not been assessed yet.