Building the Application Ahead of Deployment
Making an Application Buildable
Let's make our application setup so built assets are not saved to Git. Instead, we'll assume that assets and dependencies are built ahead of time.
On terms of a PHP application, this means building:
- Static assets
- Pulling in PHP libraries
This doesn't affect develoment too much, except to reduce merge conflicts when building static assets locally and then checking them into Git.
This does affect when we build static assets. We'll need a process to build assets before deployment.
Application Tweaks
First, we'll edit our Gulpfile. Right now it's just building SASS files to CSS. Let's also have it build our Javascript.
Update gulpfile.js:
// Disable Gulp Notify
process.env.DISABLE_NOTIFIER = true;
var elixir = require('laravel-elixir');
elixir(function(mix) {
// Minify/Concat SASS to CSS
mix.sass('app.scss');
// Minify/Concat Javascript
mix.scripts([
"app.js"
]);
}
To run Gulp:
cd ~/build-server/serialapp/repo
./node_modules/.bin/gulp --production
Next, we'll update gitignore. Just like our PHP composer packages, we don't have our built static assets to be checked into Git.
Edit the .gitignore file and append reference to the JS and CSS directories, so Git no longer tracks them:
vendor
node_modules
.env
.venv
*.py*
.idea
.vagrant
Vagrantfile
public/css/*
public/js/*
We're now ignoring our production build files! In the case of our application, those are the composer packages and static assets.