简体   繁体   English

开发模式下的ReactJS

[英]ReactJS in development mode

Is there a way to not have to build my app every time I want to run it? 有没有一种方法不必每次都运行我的应用程序? It is impossible to debug once it is compiled. 编译后就无法调试。 I have seen in videos the browser loads 100s of js files instead of one big build.js. 我已经在视频中看到,浏览器加载了数百个js文件,而不是一个大的build.js。

What do I need to change to make this happen? 我需要进行哪些更改才能实现此目的?

This is a downfall in working with modern things like React, but the answer is to use something like webpack. 这是使用诸如React之类的现代事物的失败,但是答案是使用诸如webpack之类的东西。 Webpack is able to generate the single file, but generate source maps with it as well. Webpack能够生成单个文件,但也可以生成单个文件。 Browser tools are then able to map the single build file to the original source code, making it much easier to debug. 然后,浏览器工具能够将单个构建文件映射到原始源代码,从而使调试变得更加容易。 Browserify has this ability as well, which you can use along side gulp or grunt, along with babel to compile ES6. Browserify也具有此功能,您可以将其与侧吞咽或咕unt声一起使用,并与babel一起用于编译ES6。

I'd recommend checking out webpack though, as it's becoming more commonplace. 但我建议您检查一下webpack,因为它越来越普遍。 Personally I find it a bit tricky to figure out, but once you have it running, it's great. 我个人觉得很难弄清楚,但是一旦运行起来,那就太好了。 I don't have a good example handy on using webpack with react, but there are a number of articles & tutorials out there on the subject: https://www.codementor.io/reactjs/tutorial/beginner-guide-setup-reactjs-environment-npm-babel-6-webpack 我没有一个很好的示例,可以方便地将webpack与react一起使用,但是有关该主题的文章和教程很多: https ://www.codementor.io/reactjs/tutorial/beginner-guide-setup- reactjs-environment-npm-babel-6-webpack

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

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