-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
81 lines (72 loc) · 2.15 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
(function(){
/*global -$ */
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
gulp.task('styles', function () {
return gulp.src('styles/main.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10,
includePaths: ['.'],
onError: console.error.bind(console, 'Sass error:')
}))
.pipe($.postcss([
require('autoprefixer-core')({browsers: ['last 1 version']})
]))
.pipe($.sourcemaps.write())
.pipe(gulp.dest('dist/styles'))
.pipe(reload({stream: true}));
});
gulp.task('scripts', function () {
return gulp.src('scripts/**/*.js')
.pipe($.sourcemaps.init())
.pipe($.plumber())
.pipe($.babel())
.pipe($.wrapCommonjs({
relativePath: 'scripts',
pathModifier: function (path) {
return path.replace(/.js$/, '');
}
}))
.pipe($.concat('app.js'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist/scripts/'))
.pipe(reload({stream: true}));
});
gulp.task('templates', function(){
gulp.src('templates/**/*.hbs')
.pipe($.plumber())
.pipe($.handlebars())
.pipe($.wrap('Handlebars.template(<%= contents %>)'))
.pipe($.declare({
namespace: 'JST',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe($.concat('templates.js'))
.pipe(gulp.dest('dist/scripts/'))
.pipe(reload({stream: true}));
});
gulp.task('build', ['scripts', 'templates', 'styles'], function(){});
gulp.task('serve', ['build'], function () {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['./']
}
});
// watch for changes
gulp.watch([
'*.html',
'scripts/**/*.js'
]).on('change', reload);
gulp.watch('styles/**/*.scss', ['styles']);
gulp.watch('templates/**/*.hbs', ['templates']);
gulp.watch('scripts/**/*.js', ['scripts']);
});
gulp.task('default', ['serve'], function (){});
})();