comparison 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
comparison
equal deleted inserted replaced
443:e117060eaa71 444:2f68a463cb06
1 var gulp = require('gulp');
2 var gulpif = require('gulp-if');
3 var notify = require("gulp-notify");
4 var argv = require('yargs').argv;
5
6 var less = require('gulp-less');
7 var sourcemaps = require('gulp-sourcemaps');
8 let cleanCSS = require('gulp-clean-css');
9
10 var imagemin = require('gulp-imagemin');
11
12 var jshint = require('gulp-jshint');
13 var browserify = require('gulp-browserify');
14 var uglify = require('gulp-uglify');
15
16
17 var handleErrors = function(errorObject, callback) {
18 notify.onError(errorObject
19 .toString()
20 .split(': ')
21 .join(':\n'))
22 .apply(this, arguments);
23 // Keep gulp from hanging on this task
24 if (typeof this.emit === 'function')
25 this.emit('end');
26 }
27
28
29 gulp.task('css', function() {
30 return gulp.src('wikked/assets/css/*.less')
31 .pipe(gulpif(!argv.production, sourcemaps.init()))
32 .pipe(less())
33 .on('error', handleErrors)
34 .pipe(gulpif(argv.production, cleanCSS({compatibility: 'ie8'})))
35 .pipe(gulpif(!argv.production, sourcemaps.write()))
36 .pipe(gulp.dest('wikked/static/css'))
37 });
38
39 gulp.task('fonts', function() {
40 return gulp.src('wikked/assets/font-awesome/fonts/*')
41 .pipe(gulp.dest('wikked/static/fonts'))
42 });
43
44 gulp.task('images', function() {
45 return gulp.src('wikked/assets/img/*')
46 .pipe(gulpif(argv.production, imagemin()))
47 .pipe(gulp.dest('wikked/static/img'))
48 });
49
50 gulp.task('js', function() {
51 return gulp.src('wikked/assets/js/*.js')
52 .pipe(jshint())
53 .on('error', handleErrors)
54 .pipe(browserify({
55 insertGlobals : true,
56 debug: !argv.production
57 }))
58 .on('error', handleErrors)
59 .pipe(gulpif(argv.production, uglify()))
60 .pipe(gulp.dest('wikked/static/js'));
61 });
62
63 gulp.task('default', ['css', 'fonts', 'images', 'js']);
64
65 gulp.task('watch', function() {
66 gulp.watch('wikked/assets/js/**/*.js', ['js']);
67 gulp.watch('wikked/assets/css/**/*.{css,less}', ['css']);
68 });
69