-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
executable file
·122 lines (100 loc) · 2.55 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
117
118
119
120
121
122
/**
* Tasks:
* gulp (default prod task)
* gulp css (dev css task)
* gulp js (dev js task)
* gulp watch (watcher task)
* gulp devwatch (dev watcher task)
*/
// requirements
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifyCSS = require('gulp-minify-css');
var prefix = require('gulp-autoprefixer');
var browserify = require('browserify');
var stream = require('vinyl-source-stream');
// source paths
var base = ''; // theme root
var build = { // build folders (where will the development happen?)
scss: base + 'scss/',
js: base + 'javascript/'
}
var dist = { // distribution folders (where should the output live?)
css: base + 'dist/css/',
js: base + 'dist/js/'
}
// build paths
var paths = {
css: {
src: [
build.scss + '*.scss'
],
dest: dist.css,
watch: [
build.scss + '*.scss',
build.scss + '**/*.scss'
]
},
scripts: {
main: './' + build.js + 'app.js',
utilities: build.js + 'components/*.js',
dest: dist.js,
watch: [
build.js + 'app.js',
build.js + 'components/*.js'
]
}
}
// dev css processing (unminified)
gulp.task('css', function() {
var src = paths.css.src;
var dest = paths.css.dest;
// compile the css
return gulp.src(src)
.pipe(sass({
sourceComments: 'map',
includePaths: [
build.scss
]
}))
.pipe(prefix("last 1 version", "> 1%", "ie 8"))
.pipe(gulp.dest(dest));
});
// production css processing (minified)
gulp.task('css:prod', ['css'], function() {
var src = paths.css.dest + '*.css';
var dest = paths.css.dest;
// compile the css
return gulp.src(src)
.pipe(minifyCSS())
.pipe(gulp.dest(dest));
});
// dev js processing (unminified)
gulp.task('js', function() {
var src = paths.scripts.main;
var dest = paths.scripts.dest;
// compile full js
return browserify(src)
.bundle()
.pipe(stream('core.js'))
.pipe(gulp.dest(dest));
});
// production js processing (minified)
gulp.task('js:prod', ['js'], function() {
var src = paths.scripts.main;
var dest = paths.scripts.dest;
// uglify the js
return browserify(src)
.transform({global: true}, 'uglifyify')
.bundle()
.pipe(stream('core.js'))
.pipe(gulp.dest(dest));
});
gulp.task('watch', ['css:prod', 'js:prod'], function() {
gulp.watch(paths.css.watch, ['css:prod']);
gulp.watch(paths.scripts.watch, ['js:prod']);
});
gulp.task('default', [
'css:prod',
'js:prod'
]);