How can I manage JavaScript libraries in my PHP project?

Question:

I have a PHP project and I use composer to manage libraries such as PHPMailer for sending emails.

To be able to use the installed libraries, I just include the composer autoload:

require ('vendor/autoload.php');

Recently I also needed to use other libraries, but they are JavaScript libraries, and I did the same procedure described above. The "problem" is that I have to include the JS files:

<script type="text/javascript" src="vendor/NovaBiblioteca/js/nova.mim.js">

At the end of the second library used, it doesn't seem intuitive at all.

How can I manage JavaScript libraries?

Answer:

Composer is a PHP package manager, you ca n't install Javascript libraries for it, you would have to use another Javascript specific package manager like NPM, yarn, bower or webpack, and in the javascript code you could use the webpack for automatically inject the used libraries in a single file to be included.

See here how to use the webpack https://tableless.com.br/introducao-ao-webpack/

Scroll to Top
AllEscort