I'm on a mission to use NodeJS the least amount possible. Why? Because it slows down people's builds on Chipper CI!
Luckily, Airdrop exists.
Laravel Airdrop is a tool that stores your built static assets. When you do CI runs, Airdrop checks to see if your static assets have changed.
If the assets have not changed, Airdrop downloads them from storage and places in the right place - allowing you to skip building your assets.
If they have changed, then you use Node to build your static assets as usual.
This is great for saving time in CI and deployment.
Here's how to use Airdrop.
Installing Airdrop is easy:
1composer require hammerstone/airdrop23# Add config/airdrop.php to your project4php artisan airdrop:install
There's only a few things to configure in Airdrop - and a bunch of them can be left to their defaults.
You can tell Airdrop when to decide to re-build static assets.
Triggers are specific to the environment (
APP_ENV) - each environment gets its own set of files. This is called the Configuration trigger.
The other trigger is the
FileTrigger. This tracks configured files and rebuilds assets if the files have changed.
FileTrigger will check:
- Files in the
resources(CSS, JS, etc)
- If the Webpack/Vite configuration file changes
I also add the
package-lock.json file that NPM produces.
1<?php23use Hammerstone\Airdrop\Drivers\FilesystemDriver;4use Hammerstone\Airdrop\Drivers\GithubActionsDriver;5use Hammerstone\Airdrop\Triggers\ConfigTrigger;6use Hammerstone\Airdrop\Triggers\FileTrigger;78return [9 'driver' => env('AIRDROP_DRIVER', 'default'),10 'drivers' => [11 'default' => [...],12 'github' => [...],13 ],14 'triggers' => [15 ConfigTrigger::class => [16 'env' => env('APP_ENV')17 ],18 FileTrigger::class => [19 'include' => [20 resource_path(), // default21 base_path('webpack.mix.js'), // mix default22 base_path('vite.config.js'), // vite default23 base_path('package-lock.json'), // my addition here24 ],25 ],26 ],27 'outputs' => [...],28];
You can decide where Airdrop will store static assets. Usually you just use the
FilesystemDriver here, and use Laravel's
Storage mechanism to tell Airdrop where to put the files.
disk setting related to the Laravel “disk” storage used. Using some remote storage, such as
s3, is recommended.
The GitHub Actions Driver lets you save files to the GH Actions cache, which is pretty handy!
1return [2 // The driver you wish to use to stash and restore your files.3 'driver' => env('AIRDROP_DRIVER', 'default'),45 'drivers' => [6 'default' => [7 // The class responsible for implementing the stash and restore8 // logic. Must extend BaseDriver.9 'class' => FilesystemDriver::class,1011 // The disk on which to store the built files.12 'disk' => env('AIRDROP_REMOTE_DISK', 's3'),1314 // The folder (if any) where you'd like your stashed assets to reside.15 'remote_directory' => env('AIRDROP_REMOTE_DIR', 'airdrop'),1617 // A writeable directory on the machine that builds the assets.18 // Used to build up the ZIP file before stashing it.19 'local_tmp_directory' => env('AIRDROP_LOCAL_TMP_DIR', storage_path('framework')),2021 // The skip file is an empty file that will be created to22 // indicate that asset building can be skipped.23 'skip_file' => env('AIRDROP_SKIP_FILE', base_path('.airdrop_skip')),24 ],25 ],26 // ...27];
Outputs are the files that Airdrop will store and retrieve for you. The files you “watch” via Triggers don't necessarily need to be the same files you have Airdrop save/store for you!
The defaults for Airdrop are pretty good, but of course you can configure these as needed.
1return [2 // ...3 'outputs' => [4 /*5 * Files or folders that should be included.6 */7 'include' => [8 // Mix/Webpack9 public_path('mix-manifest.json'),10 public_path('css'),11 public_path('js'),1213 // Vite14 public_path('build/manifest.json'),15 public_path('build/assets'),16 ],1718 // ...19 ],20];
Note: You likely don't want to commit static assets to your repository when using Airdrop. To avoid that, and to finish configuring Airdrop, add the following to your
1/.airdrop_skip23# Mix/Webpack4public/css/*5public/js/**67# Vite8public/build/*
When you build your app Airdrop in CI, or in a deployment script (this works great for Forge quick deploys!), you can run the following:
1# Download files, only if needed2php artisan airdrop:download34# Airdrop creates .airdrop_skip if5# it downloaded files6if [ ! -f ".airdrop_skip" ]; then7 npm ci --no-audit8 npm run dev9fi1011# Upload the files if needed12php artisan airdrop:upload