javascript - How to use Babel or webpack in a old php site with separate modules

144

I have an old project and I cannot use ES6 syntax because I don't know how to implement Babel or Webpack to transpile ES6 to ES5.

All the js modules are executed in a main.php file like this:

<script language="JavaScript" type="text/javascript"  src="<?php echo $documentroot;?>
        MAIN.js?v=<?php echo $jsVersion;?>">
</script>

How can I configure Babel to work with this old setup? the website uses jQuery. in the Babel setup page it assumes to use npm, but the project do not use node or npm, only pure php and jQuery.

Webpack also requires as prerequisite Node.js in the installation guide

215

Answer

Solution:

For practical use of Babel/Webpack, you do need the Node/npm stack available in your development environment.

The server actually serving your project does not need them available, if you package and transpile files locally (or in a CI pipeline) and deploy them onto the server, just like they were plain old JS modules.

People are also looking for solutions to the problem: php - This while loop is not working and more time, even I give the condition

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.