0

I am building a Laravel package which needs npm packages . Now the problem is that when the user install the package via composer I need him to run npm install to install the required npm packages of my package . I don't need to include it in compose.json as a post-install-cmd and don't want to call those commands programmatically .

It's like II need a way to install the packages from the package.json file of my Laravel package

is there any way to do that ?

  • If the user needs to have NPM packages from your package, then you will need to create your own `package.json` (name it like a package) and add the required packages in there, and tell the user to include your package into their `packages.json` (`npm install`), but it will have to be added as a physical path: https://stackoverflow.com/a/38417065/1998801. The normal approach is to have your packages already build and available, you then need to add the needed routes for them to be available or a command to move those built files from `dist` to the `public` folder so they are accesible – matiaslauriti Jun 11 '23 at 18:35
  • I am trying to make the package usage simple as possible because it has a lot of complex things so I need it to be done without that – Khaldoun Al Halabi Jun 12 '23 at 06:46
  • Then a normal `publish` will suffice. Just have the files already compiled and the publish command will move them from whatever folder you have them on (usually called `build`) to the `public` folder in whatever hierarchy you would like them to be in: https://laravel.com/docs/10.x/packages#publishing-file-groups – matiaslauriti Jun 12 '23 at 17:16
  • in fact I don't want to the package size to be big since I am using a lot of packages so I've created a simple command that install all the required npm packages – Khaldoun Al Halabi Jun 13 '23 at 13:01
  • That is also another solution, but I would say it is not the best one as the user will have your npm packages in the `packages.json` file added by you, if the user already has a lot of packages, it will add yours, making the file even bigger and more messy (they would have to know what exact packages you are adding so they can track their own packages), and if the user has an older version or a newer version of a package you need, you will generate issues and it is very difficult to fix and track, be careful as that may not seem very user-friendly – matiaslauriti Jun 13 '23 at 15:13
  • I have added a list of the installed packages and made sure that the user know what he is doing . thanks for helping – Khaldoun Al Halabi Jun 15 '23 at 07:44

0 Answers0