Compile EcmaScript6 to Javascript from PHP Hi,
I would like to use a web form in my site to post an EcmaScript6 code and then, from server side (php), compile it as Babel would do.
In other words, I'd like to do what Laravel Mix does with "mix.js('resources/js/app.js', 'public/js')" but in PHP.
What is the best way to do that? Is it possible?
Thanks in advance!
Can you rephrase your question please
Might be possible but do it with Node and and there'll be a lot less pain.
Thanks for your answers.
But how can I do it with Node from PHP?
The user writes the code in EcmaScript 6 in a textarea
The user clicks a submit button
The form posts the code to the server
The server receives the request with the code
The server compiles the code to plain javascript
The server creates .js file with the compiled code and saves it locally
I don't know how to do the fifth step.
Forget about PHP. You're not going to be able to transpile ES6 to ES5 with it. Unless you write your own package.
Create an express app, upload the data, save it to a file then process the file with babel.
If you really want to involve PHP then create a microservice with express and call it from PHP.
Sorry guys, but I need your help.
I'm using The Symfony Process Component to run:
$process = new Process('npm run myscript');
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
The problem is that I get the following error:
env: node: No such file or directory
If I run the command from the console everything works fine but not from PHP .
Do you have any ideas on how to make it to work?
Please sign in or create an account to participate in this conversation.