Front-end Strategy with a sprinkling of ExpressionEngine

My aim in the past while has been pointed towards front-end development, and exploring the different ways in which to produce a tidy result.

These examples point to ExpressionEngine paths, but you can customise them to any project you’re working on. I’m relatively new to the ExpressionEngine game, and some of what I’m going to outline will be eventually replaced by Niall O’Brien’s EE Foundation generator, so that’s definitely something to keep an eye on.

As with many things, we start with Gulp. This will handle our assets and do some nifty things such as generating our critical CSS and automatically injecting our Bower components whenever we update them. See below for an example setup:

var gulp = require('gulp');
var spawn = require('child_process').spawn;
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var runSequence = require('run-sequence');
var penthouse = require('penthouse');
var cleanCSS = require('clean-css');
var fs = require('fs');

// load plugins
var $ = require('gulp-load-plugins')();

gulp.task('penthouse', ['styles'], function () {
    url: ['', ''],
    css: 'assets/styles/css/main.css',
    width: 1280,
    height: 800
  }, function (err, critical) {
    var clean = new cleanCSS().minify(critical);
    fs.writeFile('system/templates/default_site/', '<style>' + clean + '</style>');

gulp.task('autoreload', function () {
    // Store current process if any
    var p;'./gulpfile.js', spawnChildren);
    // Comment the line below if you start your server by yourself anywhere else

    function spawnChildren() {
        if(p) {

        p = spawn('gulp', ['watch'], {stdio: 'inherit'});

gulp.task('styles', function () {
    return gulp.src('./assets/styles/scss/main.scss')
          errLogToConsole: true
        .on('error', $.util.log)
        .pipe($.autoprefixer('last 1 version, Explorer >= 8'))
        .pipe($.notify("Compilation complete."));

gulp.task('scripts', function () {
    return gulp.src('./assets/scripts/main.js')
        .on('error', $.util.log)

gulp.task('images', function () {
    return gulp.src('assets/graphics/**/*')
            optimizationLevel: 3,
            progressive: true,
            interlaced: true
        .pipe(reload({stream:true, once:true}))

gulp.task('build', function() {
    runSequence('wiredep', 'scripts', 'styles');

gulp.task('default', function () {

gulp.task('serve', ['styles', 'scripts', 'wiredep'], function () {
    browserSync.init(null, {
        proxy: "",
        logInfo: 'info',
        open: 'external',
        hostnameSuffix: ""
    }, function (err, bs) {
        console.log('Started connect web server on ' + bs.options.urls.external);

// inject bower components
gulp.task('wiredep', function () {
    var wiredep = require('wiredep').stream;
            devDependencies: true,
            exclude: "/assets/lib/jquery/dist/jquery.js"

gulp.task('watch', ['serve'], function () {

    // watch for changes['./system/templates/default_site/**/*.html'], reload);'assets/styles/scss/**/*.scss', ['styles']);'assets/scripts/**/*.js', ['scripts']);'bower.json', ['wiredep']);

This is just the standard-fare Gulp setup. We’ve got tasks for watching and compiling our assets. It’s the structure of these assets that I want to talk about.

Styles #

I’m using Sass (SCSS syntax), and I’m borrowing heavily from MVCSS for the structure. It’s a simplified version (i.e. I’ve left things out) to a point where I find it easier to manage.

Core #

This is the foundation of the project, where we establish defaults on tag-level elements, define variables, layouts, mixins… The files in here might go as follows:

  • _base.scss — our tag-level styles.
  • _config.scss — definition of our variables, fonts etc…
  • _helpers.scss — mixins, placeholders, utility classes.
  • _layout.scss — grid-type classes.
  • _reset.scss — I like to use normalize.css



I accept comments via email, and clicking "Add Comment" will open your default email client. If the thoughts of your native email client opening horrifies you, you can instead email your comment to

Add Comment