reactjs / react-php-v8js

PHP library that renders React components on the server
Other
1.33k stars 127 forks source link

usage with gulp? #30

Open aprilmintacpineda opened 7 years ago

aprilmintacpineda commented 7 years ago

this is the usage example you provided:

// the library
$react_source = file_get_contents('/path/to/build/react.js');
// all custom code concatenated
$app_source = file_get_contents('/path/to/custom/components.js');

$rjs = new ReactJS($react_source, $app_source);
$rjs->setComponent('MyComponent', array(
  'any'   =>  1,
  'props' =>  2
  )
);

/// ...

// print rendered markup
echo '<div id="here">' . $rjs->getMarkup() . '</div>';

/// ...

// load JavaScript somehow - concatenated, from CDN, etc
// including react.js and custom/components.js

// init client
echo '<script>' . $rjs->getJS("#here") . '</script>'; 

/// ...

// repeat setComponent(), getMarkup(), getJS() as necessary
// to render more components

I'm not sure if the following lines will be applicable if I am using gulp and laravel-elixir to mix all my scripts into a single file.

$app_source = file_get_contents('/path/to/custom/components.js');
echo '<script>' . $rjs->getJS("#here") . '</script>';
andrewpillar commented 7 years ago

It would perhaps be best to keep the React source in a separate file for component rendering. But other than that if you're mixing all of your component script files into one file then you should have no issues.