-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
64 lines (54 loc) · 1.89 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
var $,
fs = require('fs'),
del = require('del'),
gulp = require('gulp'),
path = require('path'),
clean = require('gulp-clean'),
runSequence = require('run-sequence'),
gulpLoadPlugins = require('gulp-load-plugins');
$ = gulpLoadPlugins();
gulp.task('default', ['clean'], function () {
runSequence('copy', 'js', 'inject-css');
});
gulp.task('clean', function () {
del.sync('./dist/');
});
gulp.task('watch', ['clean'], function() {
runSequence('copy', 'js', 'inject-css', function () {
return gulp.watch(['app/**/*.{js,html,scss}'], function () {
runSequence('clean', 'copy', 'js', 'inject-css');
});
});
});
gulp.task('copy', function() {
return gulp.src('assets/img/*.*')
.pipe(gulp.dest('./dist/img'));
});
gulp.task('js', function() {
return gulp.src(['app/**/*.{js,html}'])
.pipe($.sourcemaps.init())
.pipe($.if('*.html', $.crisper())) // Extract JS from .html files
.pipe($.if('*.js', $.babel()))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('.tmp/'))
.pipe(gulp.dest('dist/'));
});
gulp.task('sass', function() {
return gulp.src('./app/scss/**/*.scss')
.pipe($.sass().on('error', $.sass.logError))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('inject-css', ['sass'], function() {
return gulp.src('./dist/html/**/*.html', {base: './dist/html'})
.pipe($.tap(function(file, t) {
var filename = path.basename(file.path).replace(/html$/, 'css');
return gulp.src(file.path, {base: './dist/html'})
.pipe($.replace(/\/\* inject:css \*\//,
function() {
var style = fs.readFileSync('./dist/css/' + filename, 'utf8');
return style;
}))
.pipe(clean())
.pipe(gulp.dest('./dist/html'));
}));
});