4 ms·
Starting a "new react project" should be basically creating an HTML file, and adding a script tag linking to React the JS library. Why are these developers alwa
by throw_m239339 4y ago
Starting a "new react project" should be basically creating an HTML file, and adding a script tag linking to React the JS library. Why are these developers always trying to obfuscate everything with tons and tons of layers of indirection all the time? You don't need to "bundle" anything and certainly not use some server just to add Javascript to a page (unless it's a matter of CSP of course) and you should certainly not have to rely on nodejs or cli tool X,Y,Z...
Somehow the JS/Node dev community managed to re-invent JEE web profile, and is very close to re-invent Glassfish as well at that point, but worse because it didn't learn anything from Java enterprise... this madness needs to stop.
- KRAKRISMOTT 4y agoBecause it's slow. Hard to do treeshaking if everything is in random dependencies that need to be downloaded at runtime. You also get a flash of white if you don't pre-render your sites.
- super256 4y agoI honestly find this way more intuitive than JEE profiles. It just makes sense when you take react as what it is: a library. Now, if you want amenities like a router you need to build it yourself or use something existing. 99.9% of people want this, so why not point them into the right direction?
- jameshart 4y agoYou can actually still do this, and it is kind of a shame it's not documented on react.dev You need to pull in react, plus Babel standalone, and then you can use <script type="text/jsx"> tags, which means you can bootstrap react components onto your page. But you are going to be basically running a compiler in your user's web browser. That's fine if you want to run that way, but Babel has docs that explain why you probably shouldn't (https://babeljs.io/docs/babel-standalone#when-not-to-use-babelstandalone https://babeljs.io/docs/babel-standalone#when-not-to-use-bab...). All you need is these two scripts: <script crossorigin src="https://unpkg.com/@babel/standalone/babel.js"></script> <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script> [Edit - also need ReactDOM, sorry: <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script> ] I think it would help if more react tutorials started from here, because it shows why you need a build process. Here, as a JSFiddle: the React 'Hello World' they don't want you to see: https://jsfiddle.net/smLa1bco/ https://jsfiddle.net/smLa1bco/
- brailsafe 4y agoBuilding up my initial knowledge like you describe was the only way I could generate the enthusiasm for working on top of so many layers of abstraction.
- alex_sf 4y agoBecause they _need_ cool tool A, utility library B, theme C, and then helper library D because B doesn't work quite right.
- rk06 4y agoBecause react is not developed with that usecase in mind. And it is not recommended for production anyway. If you really need to use html with script tag, go with Vue/alpine