-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·116 lines (103 loc) · 3.36 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* http://macr.ae/article/gulp-and-babel.html
* http://egorsmirnov.me/2015/05/25/browserify-babelify-and-es6.html
* http://jpsierens.com/tutorial-javascript-es6-babelv6/
* http://hazmi.id/building-with-gulp-1-compile-less-watch-changes-and-minify-css/
*
* Packgages:
* https://www.npmjs.com/package/pump
* https://www.npmjs.com/package/gulp-uglify
*/
var gulp = require('gulp')
var sourcemaps = require('gulp-sourcemaps')
var livereload = require('gulp-livereload')
// JavaScript development.
var browserify = require('browserify')
var babelify = require('babelify')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var uglify = require('gulp-uglify')
// Less compilation.
var less = require('gulp-less')
// CSS compilation.
var concat = require('gulp-concat')
var cleanCSS = require('gulp-clean-css')
var concatCss = require('gulp-concat-css') // optional
// HTML compilation.
var htmlmin = require('gulp-htmlmin');
// Task to compile js.
// https://gist.github.com/alkrauss48/a3581391f120ec1c3e03
// http://blog.revathskumar.com/2016/02/browserify-with-gulp.html
gulp.task('compile-js', function () {
// app.js is your main JS file with all your module inclusions
return browserify({
extensions: ['.js', '.jsx'],
entries: 'javascripts/app.js',
debug: true
})
.transform('babelify', { presets: ['es2015', 'react'] })
.bundle()
.pipe(source('bundle.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('dist'))
.pipe(livereload())
})
// Task to compile less.
gulp.task('compile-less', function () {
return gulp.src([
'stylesheets/*.less'
])
.pipe(sourcemaps.init())
.pipe(less())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('stylesheets'))
})
// Task to minify css.
gulp.task('minify-css', function () {
return gulp.src([
'stylesheets/style.css'
])
.pipe(sourcemaps.init())
.pipe(cleanCSS({debug: true}))
.pipe(concat('bundle.min.css'))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('dist'))
.pipe(livereload())
})
// Task to minify html.
// https://www.npmjs.com/package/gulp-htmlmin
// https://github.com/kangax/html-minifier
gulp.task('minify-html', function() {
return gulp.src('index.html')
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(concat('index.min.html'))
.pipe(gulp.dest(''));
})
// Task to copy fonts to dist.
gulp.task('compile-fonts', function() {
return gulp.src([
'fonts/*',
'node_modules/material-design-icons/iconfont/MaterialIcons-Regular.*',
'node_modules/foundation-icon-fonts/foundation-icons.*',
])
.pipe(gulp.dest('dist/fonts/'));
});
// Task to watch less & css changes.
gulp.task('watch', function () {
gulp.watch('javascripts/*.js', ['compile-js']) // Watch all the .js files, then run the js task
gulp.watch('stylesheets/*.less', ['compile-less']) // Watch all the .less files, then run the less task
gulp.watch('stylesheets/*.css', ['minify-css']) // Watch all the .css files, then run the css task
gulp.watch('stylesheets/*.css', ['compile-fonts']) // Watch all the .css files, then run the font task
})
// Development:
// Task when running `gulp` from terminal.
gulp.task('default', ['watch'])
// Production:
// Task when running `gulp build` from terminal.
gulp.task('build', ['minify-css', 'compile-fonts', 'compile-js', 'minify-html'])