1

In the React Starter Kit they bundle with Webpack the server-side code into a server.js which I assumed can be handy but then I started wondering why bundling up the server-side code in the first place, after all Node comes with its own dependency management and doesn't need that. Second, wouldn't that even make it more inefficient due to parsing one whole file?

Mahoni
  • 7,088
  • 17
  • 58
  • 115

1 Answers1

0

React code usually got written in ES6 however the Node doesn't support the es6 code yet, it can only understand es5. so if you want to use it without bundling and all the code will get complied first on the go. which will affect the performance eventually so you can use it for the development purpose but in production it is advised to use the bundled code.

So the major reason is Performance

abhirathore2006
  • 3,317
  • 1
  • 25
  • 29
  • Node, depending on the version, supports a lot of ES6: http://node.green/ You can also transpile your es6 server code using babel without using WebPack and WebPacking the server doesn't necessarily improve the performance. – dting Nov 15 '16 at 07:58
  • however to execute react code you will need webpack if it hasn't been compiled , on the other hand compiled code can be executed directly using node – abhirathore2006 Nov 15 '16 at 08:08
  • We might be talking in circles but [webpack](https://webpack.github.io/docs/what-is-webpack.html) is a module bundler. It is able to transpile ES6 and JSX code using loaders however you can do the same thing using [babel without webpack](https://facebook.github.io/react/docs/installation.html). Babel is able to output the transpiled code to files, not "on the fly", to be run by your node server. – dting Nov 15 '16 at 08:38
  • yeah you are right, still handling 1000's of import from different files will definitely impact the performance instead of just one file – abhirathore2006 Nov 15 '16 at 08:41