简体   繁体   English

我可以使用源映射和捆绑文件来检索原始反应代码吗

[英]Can I use a sourcemap and bundle file to retrieve original react code

I have these two files on my server:我的服务器上有这两个文件:

/react/build/static/js/stats.js

and

/react/build/static/js/main.5c7483.js

In the stats.js file, it has this line at the bottom:stats.js文件中,它在底部有这一行:

//# sourceMappingURL=main.8c33616f.js.map (I noticed the filename does not match) //# sourceMappingURL=main.8c33616f.js.map (我注意到,文件名匹配)

The react app works fine, but I want to make some small changes. react 应用程序运行良好,但我想进行一些小的更改。 However, the developer has told me they completely lost the original source files due to a hard drive failure.但是,开发人员告诉我,由于硬盘驱动器故障,他们完全丢失了原始源文件。

Is it possible to recover source files (or even anything that resembles source code?) I found this debundle package but couldn't get the configuration to work properly.是否可以恢复源文件(甚至任何类似于源代码的文件?)我找到了这个debundle包,但无法使配置正常工作。

They told me the project was created using create-react-app .他们告诉我该项目是使用create-react-app

In chrome dev tools, it says "Source Map Detected" - but using ctrl+p does not show any components.在 chrome 开发工具中,它显示“检测到源地图” - 但使用ctrl+p不会显示任何组件。 Just a few random js files like page.js, inject.js, common.js, etc只是一些随机的 js 文件,如 page.js、inject.js、common.js 等

Well, this answer is late but just in case other people come here looking for answers (like me), here's how I solved it:好吧,这个答案来晚了,但以防万一其他人来这里寻找答案(像我一样),这是我解决的方法:

If you're lucky and the developers generated and uploaded the source maps then you shouldn't have any issue accessing the source codes.如果您很幸运并且开发人员生成并上传了源映射,那么访问源代码应该不会有任何问题。

I am not allowed to embed images yet so you may have to use the image links provided to see sample images.我还不允许嵌入图像,因此您可能必须使用提供的图像链接来查看示例图像。

Using Chrome(or any modern browser), browse to the website where the react app is hosted.使用 Chrome(或任何现代浏览器),浏览到托管 react 应用程序的网站。 Right-click anywhere on the page and select Inspect .右键单击页面上的任意位置并选择Inspect Ctrl+Shift+I works too. Ctrl+Shift+I 也有效。

This will open up the dev tools window.这将打开开发工具窗口。 Select the Sources tab.选择来源选项卡。 Image showing the inspector tabs with the Sources option highlighted图像显示检查器选项卡,其中突出显示了“来源”选项

Depending on the website's dependencies, you'll probably see several folders here.根据网站的依赖项,您可能会在此处看到多个文件夹。 The first folder will be titled similar to the name of the website's URL.第一个文件夹的标题类似于网站 URL 的名称。 Open that up, that's where the sources for your website is located.打开它,这是您网站的来源所在的位置。 Opening that folder will show yet another list of folders (assets, static, modules, react-components, src).打开该文件夹将显示另一个文件夹列表(assets、static、modules、react-components、src)。

At this point, you may think your source codes are inside the src folder but that's not where yours are.此时,您可能认为您的源代码在src文件夹中,但那不是您的所在。 To find yours, open up the static folder.要找到你的,打开静态文件夹。 Selecting the static folder选择静态文件夹

This folder has three inner folders: css, js and node_modules .这个文件夹有三个内部文件夹: css, js 和 node_modules Your JS source files are inside the js folder so that's where to look for your source codes.您的 JS 源文件位于js文件夹中,因此您可以在该文件夹中查找源代码。 Image showing the expanded js folder显示展开的 js 文件夹的图像

So that's it.就是这样了。 I hope this helps.我希望这有帮助。 It definitely did help me when I needed it!当我需要它时,它确实帮助了我!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM