PHP Library for JSX Compilation

- 1 answer

Ad

I have used the following code for importing React JavaScript library and JSX compiler:

<script src="build/react.js"></script>
<script src="build/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js">
</script>

I want to compile JSX using a server-side library, instead of using

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js">
</script>

Which is around 1MB. So, is there any PHP Library available for JSX Compilation?

Ad

Answer

Ad

You really shouldn't be using Babel in the browser. Take the time to learn how to set up a build environment that uses Babel to precompile your JavaScript. The typical workflow uses Babel in conjunction with either Webpack or Browserify to bundle your modules.

Official documentation:

If you need React server side rendering within a PHP backend, you might like to check out https://github.com/reactjs/react-php-v8js. It doesn't do JSX compilation, just server side rendering. So you still need to precompile your JavaScript.

Ad
source: stackoverflow.com
Ad