Wellfire's Django-centric front-end build process using Gulp.
Wellfire uses Jade (for HTML), Stylus (for CSS), and CoffeeScript (for JS) as they most align to the coding style dictated by Python.
- gulp: gulp build processor
- browser-sync: live sync front-end editting
- coffee-script: process coffescript files (or run gulp)
- del: cleans up unneccesary files.
- gulp-autoprefixer: update CSS files with supported prefixes
- gulp-changed: check files for changed status. speeds up front-end processing, used on media files
- gulp-coffee: process coffeescript -> javqascript within gulp build flow
- gulp-coffeelint: lint coffeescript files
- gulp-concat: concatenate coffeescript and resulting javascript files
- gulp-csso: minify CSS files
- gulp-exec: run commands from CLI
- gulp-filter: filter files within stream
- gulp-if: logic for build flow
- gulp-image-embed: process css files and replace linked background images with data URIs
- gulp-imagemin: compress images, may require imagemin processors
- gulp-jade: process jade -> HTML files within gulp build flow
- gulp-load-plugins: easy loading plugins for gulp
- gulp-newer: check for newer files, used with jade, stylus, coffeescript
- gulp-plumber: checks for errors within streams and keeps gulp running without fatal errors (usually)
- gulp-sizereport: check for your final and gzip size of files
- gulp-sourcemaps: maps coffeescript to javascript files
- gulp-stylus: process stylus -> CSS files within gulp build flow
- gulp-uglify: minimizes your js files
- gulp-util: adds helpful utilities to gulp. color CLI, get environment variables
- gulp-watch: extends gulp watch
- imagemin-gifsicle: imagemin required processor, circumvents npm build errors
- imagemin-jpegtran: imagemin required processor, circumvents npm build errors
- imagemin-optipng: imagemin required processor, circumvents npm build errors
- imagemin-pngquant: imagemin required processor, circumvents npm build errors
- imagemin-svgo: imagemin required processor, circumvents npm build errors
- js-yaml: process YAML config files
- main-bower-files: run bower processing
- marked: process Markdown files
- run
npm install --global gulp - run
npm install - open
gulpfile.jsand switch out thesite_filevalue with the correct path for yoursite.yamlfile (already set up in this project). Wellfire puts the front-end configuration within the front-end dev area (_dev) to keep the base folder clean and not step on any Django/Server configurations that need to move to various server environments. - run
gulporgulp helpto see the options
You can view your site at the given Django dev server localhost (localhost:8000 here). However,
when running front-end watches, you'll want to use Browser-Sync. For the first time run, add the
flags --watch --ui, which will start your file watches, run Browser-Sync, and open B-S's UI. The
UI will help you launch a browser-synced proxy of the Django dev server.
By using Browser-Sync, we are removing the need to embed livereload script directly into the templates. This is a serious win.
We do not recommend the use of combining media queries. Once completed, the order of the combined queries is not logical and unforeseen layout issues occur. Please gzip compress the CSS files for better usage of minification.
We do not recommend using bower files and instead use CDN versions instead, if possible. This will lessen the amount of concurrent same-host downloads initially and users may already have dependencies already downloaded on their computer, allowing for a cached version.
Lately we've had build errors with this plugin. However, it is the best that we've run into for its functionality. Therefore, the individual dependencies are installed as well. This seems to circumvent the build errors.
If you still receive build errors, try removing gulp-imagemin from package.json, run
npm install, then replace gulp-imagemin, and run npm install again.
This is a nifty script that will parse your css files for background-images and the like and convert
them to base64 data URIs. This is up to you if it saves some bytes and transfer costs. Run with
--sizereport to see what your savings are. Note: There is not much gzip compression on images,
you may see some gzip dividends with the data URIs.
We minify CSS and JS by default as we generally use Chrome Dev Tools for checking out problem issues.
By not minifying at the outset, we may forget to minify for commits/promotions. Use --unminify if
you need to look at a processed file without minification.
We do not minify HTML files as these are run through Django Templates and have Django template tags embedded in them. HTML minifiers appear to choke on some of the logic embedded with the template tags. These files are gzipped on the server regardless and so should be fine with the gzip compression.
Configuration for Gulp is located in the _config/site.yaml file. The following is a breakdown of
each section
Static data used within the Jade templates
Static variables used within the Django template portion of the HTML templates
Booleans used within the Jade templates to process script tags. The dev_server key-value pair will
perclude the given development/staging server from Google Analytics.
Booleans used with the Jade templates to process link tags or conditional comments
- type: determines what type of project is being built (
static,django,jekyll). For this project, we've remove the Gulp Static and Jekyll portions as they are not needed. - host: generally
localhost, but this is for serving a static site and is used by browser-sync for proxing off the Django development server. - port: the port that browser-sync will proxy off of.
Important object declarations for usaage in Gulp's pre-processors. Used for the glob object, which
dicates which files Gulp should include in its streams. Usage of a ! before a file name instructs
Gulp to not include that file or structure.
For CoffeeScript, the glob determines what is concactenated on processing and the output
key:value determines what the concactenated file is called.
This structure maps where development files live (src) and where they end up (build). The data
key:value pair is a folder that Gulp will process for YAML files for static content structures or
fixtures and introduce into the Jade templates.
For build.static, this is used to map where the static folder for Django is kept.