Mercurial > wikked
diff gulpfile.js @ 444:2f68a463cb06
cm: Replace Grunt/RequireJS with Gulp/Browserify.
Yes, I know, this sounds like it's 2014 or something, and cool kids are now
actually on webpack or whatever.
Anyway, besides the change to a `gulpfile`, it also moves all dependencies
over to `npm` (via the `package.json` file), which cleans up the repository
nicely, and replaces awkward JS imports with simpler `require` statements.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 03 Jan 2018 00:51:59 -0800 |
parents | |
children | 8ee6e7649aba |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gulpfile.js Wed Jan 03 00:51:59 2018 -0800 @@ -0,0 +1,69 @@ +var gulp = require('gulp'); +var gulpif = require('gulp-if'); +var notify = require("gulp-notify"); +var argv = require('yargs').argv; + +var less = require('gulp-less'); +var sourcemaps = require('gulp-sourcemaps'); +let cleanCSS = require('gulp-clean-css'); + +var imagemin = require('gulp-imagemin'); + +var jshint = require('gulp-jshint'); +var browserify = require('gulp-browserify'); +var uglify = require('gulp-uglify'); + + +var handleErrors = function(errorObject, callback) { + notify.onError(errorObject + .toString() + .split(': ') + .join(':\n')) + .apply(this, arguments); + // Keep gulp from hanging on this task + if (typeof this.emit === 'function') + this.emit('end'); +} + + +gulp.task('css', function() { + return gulp.src('wikked/assets/css/*.less') + .pipe(gulpif(!argv.production, sourcemaps.init())) + .pipe(less()) + .on('error', handleErrors) + .pipe(gulpif(argv.production, cleanCSS({compatibility: 'ie8'}))) + .pipe(gulpif(!argv.production, sourcemaps.write())) + .pipe(gulp.dest('wikked/static/css')) +}); + +gulp.task('fonts', function() { + return gulp.src('wikked/assets/font-awesome/fonts/*') + .pipe(gulp.dest('wikked/static/fonts')) +}); + +gulp.task('images', function() { + return gulp.src('wikked/assets/img/*') + .pipe(gulpif(argv.production, imagemin())) + .pipe(gulp.dest('wikked/static/img')) +}); + +gulp.task('js', function() { + return gulp.src('wikked/assets/js/*.js') + .pipe(jshint()) + .on('error', handleErrors) + .pipe(browserify({ + insertGlobals : true, + debug: !argv.production + })) + .on('error', handleErrors) + .pipe(gulpif(argv.production, uglify())) + .pipe(gulp.dest('wikked/static/js')); +}); + +gulp.task('default', ['css', 'fonts', 'images', 'js']); + +gulp.task('watch', function() { + gulp.watch('wikked/assets/js/**/*.js', ['js']); + gulp.watch('wikked/assets/css/**/*.{css,less}', ['css']); +}); +