How to organize js code when you are using v8js engine (php) for prerending react component?

400 views Asked by At

The problem is that I have to send to v8js file like this

let HelloWorld = function(props){
    return (
        React.createElement('h1', null, 'Hello World!'+props.count)
    );
}

I mean no import and no export lines are acceptable

But for webpack I need to have file like this

import React, { Component } from 'react';

let HelloWorld = function(props){
    return (
        React.createElement('h1', null, 'Hello World!'+props.count)
    );
}

export default HelloWorld;

I can't find how to include file like for v8js code to webpack correctly

I want to use one component in v8js and webpack at the same time without copy paste.

1

There are 1 answers

0
Sergey Filatov On

I know simple solution but it is not beautiful

do this before sending to v8

$appsrc = preg_replace('/(import.*?;)/', '', $appsrc);
$appsrc = preg_replace('/(export.*?;)/', '', $appsrc);