Eyad Al
Eyad Al

Reputation: 23

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?

Upvotes: 2

Views: 2864

Answers (2)

odan
odan

Reputation: 4962

You can use composer to generate an optimized build of your application. All dev-dependencies are removed and the Composer autoloader is optimized for performance.

Run this command in the same directory as the project’s composer.json file:

composer install --no-dev --optimize-autoloader

You don’t have to run composer on your production server. To build a deployment "artifact" you could use Apache Ant.

Upvotes: 2

Fabien Sa
Fabien Sa

Reputation: 9480

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.

Upvotes: 5

Related Questions