taro 生产环境下,生成的sourcemap文件不对应源码,而是未压缩的产物

hec6srdp  于 8个月前  发布在  其他
关注(0)|答案(1)|浏览(77)

相关平台

微信小程序

小程序基础库: 和小程序版本无关
使用框架: React

复现步骤

操作步骤:任意一个hello word项目编译后,查看首页的源码及.map文件。
示例
taro源码(最简单的示例):
  1. import React from 'react'
  2. import { View, Text } from '@tarojs/components'
  3. import { useLoad } from '@tarojs/taro'
  4. import './index.scss'
  5. import { p } from './a';
  6. export default class Index extends React.Component {
  7. componentDidMount() {
  8. this.jump(p);
  9. }
  10. jump(b) {
  11. const a = 1;
  12. let c = a b;
  13. throw new Error('sec-error' c)
  14. }
  15. render() { return 'test'; }
  16. }
生成的sourcemap
  1. {
  2. "version": 3,
  3. "file": "pages/sec/index.js",
  4. "mappings": "kJAAMA,EAAI,MCONC,EAAqB,SAAUC,GACjC,SAASD,IAEP,OADA,OAAgBE,KAAMF,IACf,OAAWE,KAAMF,EAAOG,UACjC,CAEA,OADA,OAAUH,EAAOC,IACV,OAAaD,EAAO,CAAC,CAC1BI,IAAK,oBACLC,MAAO,WACLH,KAAKI,KAAKP,EACZ,GACC,CACDK,IAAK,OACLC,MAAO,SAAcE,GACnB,IAAIC,EAAI,EACJC,EAAID,EAAID,EACZ,MAAM,IAAIG,MAAM,YAAcD,EAChC,GACC,CACDL,IAAK,SACLC,MAAO,WACL,MAAO,MACT,IAEJ,CAxByB,CAwBvB,aC7BEM,EAAS,CAAC,uBAAyB,gBAG5BC,MAAK,IAAAC,kBAAiB,EAAW,kBAAmB,CAACC,KAAK,CAACC,GAAG,KAAMJ,GAAU,CAAC,G",
  5. "sources": [
  6. "webpack://ts-ggg/._src_pages_sec_a.js",
  7. "webpack://ts-ggg/./src/pages/sec/index.tsx?a97f",
  8. "webpack://ts-ggg/._src_pages_sec_index.tsx"
  9. ],
  10. "sourcesContent": [
  11. "const p = '123';\nexport {\n p\n};",
  12. "import _classCallCheck from \"/Users/qitmac001076/other/code/taro-demo/ts-ggg/node_modules/@babel/runtime/helpers/esm/classCallCheck.js\";\nimport _createClass from \"/Users/qitmac001076/other/code/taro-demo/ts-ggg/node_modules/@babel/runtime/helpers/esm/createClass.js\";\nimport _callSuper from \"/Users/qitmac001076/other/code/taro-demo/ts-ggg/node_modules/@babel/runtime/helpers/esm/callSuper.js\";\nimport _inherits from \"/Users/qitmac001076/other/code/taro-demo/ts-ggg/node_modules/@babel/runtime/helpers/esm/inherits.js\";\nimport React from 'react';\nimport './index.scss';\nimport { p } from './a';\nvar Index = /*#__PURE__*/function (_React$Component) {\n function Index() {\n _classCallCheck(this, Index);\n return _callSuper(this, Index, arguments);\n }\n _inherits(Index, _React$Component);\n return _createClass(Index, [{\n key: \"componentDidMount\",\n value: function componentDidMount() {\n this.jump(p);\n }\n }, {\n key: \"jump\",\n value: function jump(b) {\n var a = 1;\n var c = a + b;\n throw new Error('sec-error' + c);\n }\n }, {\n key: \"render\",\n value: function render() {\n return 'test';\n }\n }]);\n}(React.Component);\nexport { Index as default };",
  13. "import { createPageConfig } from '@tarojs/runtime'\nimport component from \"!!../../../node_modules/@tarojs/taro-loader/lib/entry-cache.js?name=pages/sec/index!./index.tsx\"\nvar config = {\"navigationBarTitleText\":\"首页\"};\n\n\nvar inst = Page(createPageConfig(component, 'pages/sec/index', {root:{cn:[]}}, config || {}))\n\n\nexport default component\n"
  14. ],
  15. "names": [
  16. "p",
  17. "Index",
  18. "_React$Component",
  19. "this",
  20. "arguments",
  21. "key",
  22. "value",
  23. "jump",
  24. "b",
  25. "a",
  26. "c",
  27. "Error",
  28. "config",
  29. "Page",
  30. "createPageConfig",
  31. "root",
  32. "cn"
  33. ],
  34. "sourceRoot": ""
  35. }

其中sourcesContent对应的源码部分,可以看出明显不是taro源码:

  1. import _classCallCheck from \"/Users/qitmac001076/other/code/taro-demo/ts-ggg/node_modules/@babel/runtime/helpers/esm/classCallCheck.js\";
  2. import _createClass from \"/Users/qitmac001076/other/code/taro-demo/ts-ggg/node_modules/@babel/runtime/helpers/esm/createClass.js\";
  3. import _callSuper from \"/Users/qitmac001076/other/code/taro-demo/ts-ggg/node_modules/@babel/runtime/helpers/esm/callSuper.js\";
  4. import _inherits from \"/Users/qitmac001076/other/code/taro-demo/ts-ggg/node_modules/@babel/runtime/helpers/esm/inherits.js\";
  5. import React from 'react';
  6. import './index.scss';
  7. import { p } from './a';
  8. var Index = /*#__PURE__*/function (_React$Component) {
  9. function Index() {
  10. _classCallCheck(this, Index);
  11. return _callSuper(this, Index, arguments);
  12. }
  13. _inherits(Index, _React$Component);
  14. return _createClass(Index, [{
  15. key: \"componentDidMount\",
  16. value: function componentDidMount() {
  17. this.jump(p);
  18. }
  19. }, {
  20. key: \"jump\",
  21. value: function jump(b) {
  22. var a = 1;
  23. var c = a b;
  24. throw new Error('sec-error' c);
  25. }
  26. }, {
  27. key: \"render\",
  28. value: function render() {
  29. return 'test';
  30. }
  31. }]);
  32. }(React.Component);
  33. export { Index as default };

期望结果

期望sourcemap对应的是taro源码

实际结果

现在结果是对应编译后的产物

环境信息

  1. 👽 Taro v3.6.23
  2. Taro CLI 3.6.23 environment info:
  3. System:
  4. OS: macOS 12.4
  5. Shell: 5.8.1 - /bin/zsh
  6. Binaries:
  7. Node: 16.20.2 - ~/.nvm/versions/node/v16.20.2/bin/node
  8. Yarn: 1.22.22 - ~/.nvm/versions/node/v16.20.2/bin/yarn
  9. npm: 8.19.4 - ~/.nvm/versions/node/v16.20.2/bin/npm
  10. npmPackages:
  11. @tarojs/cli: 3.6.24 => 3.6.24
  12. @tarojs/components: 3.6.24 => 3.6.24
  13. @tarojs/helper: 3.6.24 => 3.6.24
  14. @tarojs/plugin-framework-react: 3.6.24 => 3.6.24
  15. @tarojs/plugin-platform-alipay: 3.6.24 => 3.6.24
  16. @tarojs/plugin-platform-h5: 3.6.24 => 3.6.24
  17. @tarojs/plugin-platform-weapp: 3.6.24 => 3.6.24
  18. @tarojs/react: 3.6.24 => 3.6.24
  19. @tarojs/runtime: 3.6.24 => 3.6.24
  20. @tarojs/shared: 3.6.24 => 3.6.24
  21. @tarojs/taro: 3.6.24 => 3.6.24
  22. @tarojs/taro-loader: 3.6.24 => 3.6.24
  23. @tarojs/webpack5-runner: 3.6.24 => 3.6.24
  24. babel-preset-taro: 3.6.24 => 3.6.24
  25. eslint-config-taro: 3.6.24 => 3.6.24
  26. react: ^18.0.0 => 18.3.1
  27. react-native: 0.69.3 => 0.69.3
sdnqo3pr

sdnqo3pr1#

进一步排查后,发现只有页面会这样,页面引用的组件还是对应源码

相关问题