|
| 1 | + |
| 2 | +# Deploying |
| 3 | + |
| 4 | +To integrate Airdrop into your build process, you'll need to do a few things. |
| 5 | + |
| 6 | +## Adding the Airdrop Commands |
| 7 | + |
| 8 | +The first thing you'll need to do is run `php artisan airdrop:download` _before_ you build your assets. This is the command that will download and place your built assets, if they are available. |
| 9 | + |
| 10 | +The next thing you'll need to do is run `php artisan airdrop:upload` _after_ you build your assets. This command will store the built assets, if they aren't already stored. |
| 11 | + |
| 12 | +This will take care of downloading and uploading your assets, should that be required. |
| 13 | + |
| 14 | +Once you're done, your asset step will look something like this: |
| 15 | + |
| 16 | +```bash |
| 17 | +php artisan airdop:download |
| 18 | +npm run production |
| 19 | +php artisan airdrop:upload |
| 20 | +``` |
| 21 | + |
| 22 | +## Skipping Asset Compilation |
| 23 | + |
| 24 | +The next (and last!) thing we need to change is the skipping of the compilation of assets if it isn't required. |
| 25 | + |
| 26 | +The FilesystemDriver creates a flag file called `.airdrop_skip` if the asset building step can be skipped, so we need to check for the existence of that file. |
| 27 | + |
| 28 | +### Laravel Mix |
| 29 | +If you're using Laravel Mix you can modify your `webpack.mix.js` file to see if that file exists, and return early if it does: |
| 30 | + |
| 31 | +```js |
| 32 | +// Exit early if assets don't need to be built. |
| 33 | +if (require('fs').existsSync('.airdrop_skip')) { |
| 34 | + console.log("Assets already exist. Skipping compilation."); |
| 35 | + process.exit(0); |
| 36 | +} |
| 37 | + |
| 38 | +// Rest of the file... |
| 39 | +``` |
| 40 | +{data-filename="webpack.mix.js"} |
| 41 | + |
| 42 | +### Bash |
| 43 | + |
| 44 | +If you're not using Laravel Mix, or you want to skip several steps based on the existence of that file, you can do so using bash. |
| 45 | + |
| 46 | +```bash |
| 47 | +php artisan airdrop:download |
| 48 | + |
| 49 | +# Skip several steps if we can. |
| 50 | +if [ ! -f ".airdrop_skip" ]; then |
| 51 | + nvm install |
| 52 | + nvm use |
| 53 | + yarn install --frozen-lockfile |
| 54 | + npm run production |
| 55 | +fi |
| 56 | + |
| 57 | +php artisan airdrop:upload |
| 58 | +``` |
| 59 | + |
| 60 | +Now we're skipping multiple potentially expensive commands based on the presence of the Airdrop skip file. |
| 61 | + |
| 62 | +> Remember: If you change the path of the skip file in your configuration, you'll need to change it in your Mix / Bash file as well. |
| 63 | +
|
| 64 | + |
| 65 | + |
0 commit comments