Well this isn’t necessarily always true. The --production flag tries to do as little as possible different from the dev build. In fact: it uses all the same exact tasks. The only thing this does different is
- Filename Revving
- disable sourcemaps
- If there is a less/Sass syntax error fail the build rather than ignore it
Notice how none of those change the content of your source files. They are “meta” tasks that enable and disable tradeoffs useful in development. When I have a project that is nearing completion I will actually switch my WP_ENV to to staging and start using gulp --production
so I can start simulating exactly what is heading to staging/production. This way I am never crossing my fingers and hoping it works on deploy.
Options
1. Don’t check compiled files into source control
I recommend doing this. When you say:
You are actually saying “checking compiled files into source control sucks”.
I’ve got an article here: Build Steps and Deployment that explains how I approach deploying projects with a build process. I’m going do another write up specifically about deploying sage.
2. Be clever about checking compiled files into source control
I still don’t recommend committing compiled files to source control. But I know in some situations it is the path of least resistance. So if you are going to do it, be clever about it.
- Use git hooks to run the
--production
build and commit the files automatically. - Use a CI to automatically build and commit files.
3. Your original idea
I don’t recommend this. However: I was very clever when I built the gulpfile. So it can definitely facilitate shenanigans such as this. The variable path.dist
controls the output of all the compiled files. So maybe around here:
https://github.com/roots/sage/blob/master/gulpfile.js#L16
You can add:
if(argv.production) {
path.dist = "dist-prod/"
}
Which means
if
--production
then output everything todist-prod/
directory
The gulpfile is just javascript. This is a huge advantage over the previous grunt workflow. You can make it do anything you want.