Search code examples
phpnode.jswebpackbundlerslim

Is there a PHP bundler similar to Node's Webpack


I wrote a REST-API application using PHP Slim4 framework. However, now that I want to deploy the application. I cannot seem to find an intuitive tool like webpack to bundle my app into a few files and do the tree shaking for any unused code.

Are there any tools that people use with PHP for deployment? I'm not used to deploying PHP apps so I'm not sure what are the best practices for deploying PHP applications into the wild?


Solution

  • You don't need tree shaking in PHP, you can load needed classes using lazy loading. For that you need autoloading which can load the class file when the class is needed.

    Instead of implementing the logic yourself you should use the, de-facto standard, composer and use the PSR-4 convention to make your file paths match your namespaces.

    If you really want to have everything in one file you can use the phar "archive", you can do it manually or with tools like box but you don't need it to deploy code in production, it's usually not needed.