A mostly reasonable gulpsheet written in ES6 modules for modest projects.
- be sure
node
,npm
,yarn
andgulp-cli
are installed - run
npm i
oryarn
to install all required packages for development - run
gulp
tobuild
a new project and load thewatch
task
Project and text-editor configuration files reside in the project repo root. The
main gulpfile
lives here along side the CHANGELOG, README and other essential
config files.
Compiled code and optimized assets are built here from /src/
. BrowserSync uses
this directory for local development. The watch
task looks at this directory
and performs tasks when files change.
All gulp tasks, config files and support files reside here.
Here’s where the work is done. The files open in your text editor of choice
should all be working in /src/
.
The gulpfile
is the entry point to all gulp configuration. Configuration and
task development have been made as modular as possible.
Environment-specific variables are loaded securely through .env
which is NOT
under version control. The gulpfile
then loads in all the gulp tasks. Order is
unimportant here (but alphabetical is encouraged).
Configure gulp tasks with the help of CLI arguments. Current supporting CLI arguments include:
--nobs
or--nobrowsersync
to disable Browser Sync--nomin
to disable minification of CSS, JS and HTML output files--ftp
to enable deployment via FTP--sftp
to enable deployment via SFTP--url "[url]"
to test a URL with Page Speed Insights ingulp psi
task
The common error handling function should be called from the errorHandler
object that is loaded from error.js
Error messages will display without breaking the watch
workflow zen.
Globs and file path references should be called from the globs
object that is
loaded from globs.js
.
If a project requires gulp
to be somewhere other than root
, basic file paths
can be updated in the variables at the top of the file which will then cascade
down into the exported module.
Environment-specific variables are stored here. This file is under the
.gitignore
file list to prevent sensitive and secure information from being
committed to the Git repo.
Use this file to store deploy connection host settings, database information,
usernames and passwords. By default the deploy
task will reference this file.
In practice, running gulp
should be the only command required for workflow
zen. Gulp will build the complete project, spin up BrowserSync for local
development and watch files.
Gulp will actively watch files and run tasks accordingly on file change. If
everything is working, the developer should only need to head back to the
terminal to cancel the watch
task with Ctrl+C at the end of work. Workflow zen
is achieved with a “set it and forget it” mentality in the land of gulp.
However, there are a great deal of sub-tasks that can still be called directly outside of this workflow. Calling tasks by name can be useful when debugging, while developing new features or simply for calling a specific task on demand for better/faster performance.
Example: If the project is already built and waiting, jump right into the
action with gulp watch
and get to coding.
Every defined task listed by terminal command and a brief description.
NOTE: Some tasks may contain sub-routines that are not explicitly expressed here.
The default task can also be called with gulp default
, but why waste the
effort on extra characters. Calls build
and then watch
.
First /dist/
is nuked with clean
and then the build order for tasks is
called. Next img
, html
, nunjucks
, css
, js
, static
and inline
tasks
are all called to build a complete project to /dist/
.
Deletes /dist/
completely. Scorched earth. Only the directory itself remains.
Builds the main stylesheet from the SCSS project files. Runs the CSS through
Autoprefixer to manage browser vendor prefixes. Images less than 8kb are base64
inlined. PX units are converted to REM units. An inline style block version is
created along side the working version. Files are moved into place in /dist/
.
If the command line argument --nomin
is set minification will be disabled and
sourcemap support will be enabled.
Deploy complete project to server as defined by .env
environment-specific
variables. Uses FTP or SFTP depending on CLI arguments.
Run ESLint on JS files in /src/
.
Correct special text characters erroneously copy pasted into the HTML and minify.
Losslessly compresses image assets and moves them into place. Handles JPG, PNG, GIF and SVG file types.
Inline scripts directly into HTML for performance gains. Use boolean HTML
attribute inline
to target scripts and links for inline.
Transform ES6 into browser friendly ES5 with babelify
and browserify
.
Bundles are minified by default. If the command line argument --nomin
is set
minification will be disabled and sourcemap support will be enabled.
Run all the various linters on files in /src/
.
Contains all the power of html
but with the distinction of building .njk
template files into HTML first. Converts Markdown blocks or imports via
{{ markdown }}
command.
Format repo files with prettier
.
Run tests with Google PageSpeed Insights. One test runs for mobile and one for
desktop. Supply the URL to be tested via CLI argument --url "[url]"
. The CLI
has a limit of 5s per result set, which is better than the web interfaces 60s
turn around time on cached results.
Run Sass Lint on SCSS files in /src/
.
Quick and dirty local performance audit. Output file size reports on /dist/
.
Moves miscellaneous files from /src/
into place in /dist/
. This task carbon
copies files without affecting changes. This manages root level assets such as
configuration and icon files. Handles /fonts/
and other theme assets by
default.
Listens for changes in /src/
and builds to /dist/
. Listens for changes in
/dist/
and deploys to remote server. File transfer work is time intensive, so
gulp
only uploads the files in need, as needed.
Configure gulp watch
settings via CLI arguments
If BrowserSync is enabled, watch
creates a secure public URL to share your
local sites with any Internet-connected device on the local network. Perfect for
browser and device testing. Great for collaborative work without all the “ok hit
refresh” chat spam back and forth.
BrowserSync will manage browser refresh and device sync on file change and uses
/dist/
as base for the server. The terminal provides all the URLs needed for
making use of BrowserSync. Develop using these URLs and NOT with a simple
local-file approach.
[BS] Access URLs:
--------------------------------
Local: http://localhost:9000
External: http://10.1.10.235:9000
--------------------------------
UI: http://localhost:3001
UI External: http://10.1.10.235:3001
--------------------------------
[BS] Serving files from: dist/
The major workflow tasks come with shortcut commands for the lazy developer.
gulp
==gulp default
gulp b
==gulp build
gulp c
==gulp clean
gulp d
==gulp deploy
gulp w
==gulp watch
[gulp-khup] is written in the syntax of
Gulp 4.0. This allows for use of some
features like since
, series
and parallel
. See the
GitHub page for code examples.
[gulp-khup] is designed to be a starting off point for projects. Some projects will require adding new tasks or updates to the existing tasks.
Knowing is half the battle.
- http://gulpjs.com/
- https://markgoodyear.com/2014/01/getting-started-with-gulp/
- http://makina-corpus.com/blog/metier/2015/make-your-gulp-modular
- http://moonshotproject.github.io/moondash/building/packaging/2014/11/26/modular-gulp.html
- https://bugsnag.com/blog/replacing-the-rails-asset-pipeline-with-gulp
- http://drewbarontini.com/articles/building-a-better-gulpfile/
- http://macr.ae/article/splitting-gulpfile-multiple-files.html
MIT