Skip to content

Instantly share code, notes, and snippets.

@andreasnymark
Last active April 30, 2019 08:44
Show Gist options
  • Save andreasnymark/dee45d2cda3deb3de44b7d4ca856b0f9 to your computer and use it in GitHub Desktop.
Save andreasnymark/dee45d2cda3deb3de44b7d4ca856b0f9 to your computer and use it in GitHub Desktop.
gulpfile.js
const { src, dest, task, series, watch } = require( 'gulp' );
const plumber = require( 'gulp-plumber' );
const prefix = require( 'gulp-autoprefixer' );
const concat = require( 'gulp-concat' );
const uglify = require( 'gulp-uglify' );
const header = require( 'gulp-header' );
const rename = require( 'gulp-rename' );
const media = require( 'gulp-group-css-media-queries' );
const nano = require( 'gulp-cssnano' );
const less = require( 'gulp-less' );
const style_comment = '/* '
+ '\nCopyright?'
+ '\n*/\n';
const script_comment = '/* '
+ '\nCopyright?'
+ '\n*/\n';
const sources = {
app: {
less: {
name: 'styles.css',
build: 'assets/styles',
src: [ 'src/styles/*.less' ]
},
js: {
name: 'scripts.js',
build: 'assets/scripts',
src: [ 'src/scripts/utils.js', 'src/scripts/!(init,utils)*.js', 'src/scripts/init.js' ]
}
}
};
function styles( cb ) {
return src( sources.app.less.src, { allowEmpty: true } )
.pipe( plumber() )
.pipe( concat( sources.app.less.name ) )
.pipe( less() )
.pipe( media() )
.pipe( prefix( {
browsers: [ 'last 2 versions' ],
cascade: false
} ) )
.pipe( dest( sources.app.less.build ))
.pipe( nano() )
.pipe( header( style_comment ) )
.pipe( rename( { suffix: '.min' } ) )
.pipe( dest( sources.app.less.build ));
cb();
}
function scripts( cb ) {
return src( sources.app.js.src, { allowEmpty: true } )
.pipe( plumber() )
.pipe( concat( sources.app.js.name ) )
.pipe( dest( sources.app.js.build ) )
.pipe( uglify() )
.pipe( rename( { suffix: '.min' } ) )
.pipe( dest( sources.app.js.build ) );
cb();
}
exports.default = function() {
styles();
scripts();
}
watch( sources.app.less.src, { ignoreInitial: true, allowEmpty: true }, styles );
watch( sources.app.js.src, { ignoreInitial: true, allowEmpty: true }, scripts );
document.onreadystatechange = function () {
if ( document.readyState === 'interactive' ) {
// …
}
}
/**
* A collection of utility functions.
**/
var scope = scope || {};
scope.utils = ( function ( window, document ) {
"use strict";
/**
* Check if element already contains class
* @method hasClass
* @param {HTMLElement} elem - DOM Element
* @param {String} cls - Class name
* @return {Boolean} bool
**/
var hasClass = function ( elem, cls ) {
// …
};
return {
hasClass: hasClass,
};
}( window, document ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment