-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (76 loc) · 2.96 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
var path = require('path');
var gulp = require('gulp');
var babel = require('gulp-babel');
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
var del = require('del');
var dotPreparse = require('gulp-dot-preparse');
var header = require('gulp-header');
var sass = require('gulp-sass');
const clientSourceFolder = path.join('src', 'client');
const clientDistFolder = path.join('dist', 'client');
const jsDestinationFolder = path.join(clientDistFolder, 'js');
const mainHtmlSrc = path.join(clientSourceFolder, 'index.html');
const fontsSrc = path.join(clientSourceFolder, 'fonts', '**', '*');
const imagesSrc = path.join(clientSourceFolder, 'images', '**', '*');
const extJsSrc = path.join(clientSourceFolder, 'js', 'ext', '**', '*');
const jsToTranspile = path.join(clientSourceFolder, 'js', '*.js');
const templatesLocation = path.join(clientSourceFolder, 'templates', '**', '*.jst');
gulp.task('sass', function () {
const mainSassFile = path.join(clientSourceFolder, 'scss', 'app.scss');
const cssDestinationFolder = path.join(clientDistFolder, 'css');
return gulp.src(mainSassFile)
.pipe(sass())
.pipe(cleanCSS({ compatibility: 'ie9' }))
.pipe(gulp.dest(cssDestinationFolder));
});
gulp.task('babel', function () {
return gulp.src(jsToTranspile)
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest(jsDestinationFolder));
});
gulp.task('templates', function () {
return gulp.src(templatesLocation)
.pipe(dotPreparse({
root: path.join(clientSourceFolder, 'templates'),
global: 'render',
templateSettings: {
varname: 'model'
}
}))
.pipe(concat('templates.js'))
.pipe(header('window.render={};'))
.pipe(gulp.dest(jsDestinationFolder));
});
gulp.task('copy', function () {
gulp.src(mainHtmlSrc).pipe(gulp.dest(clientDistFolder));
const fontsDist = path.join(clientDistFolder, 'fonts');
gulp.src(fontsSrc).pipe(gulp.dest(fontsDist));
const extJsDist = path.join(clientDistFolder, 'js', 'ext');
gulp.src(extJsSrc).pipe(gulp.dest(extJsDist));
// To delete after development
const imagesDist = path.join(clientDistFolder, 'images');
gulp.src(imagesSrc).pipe(gulp.dest(imagesDist));
return;
});
gulp.task('watch:client', function () {
gulp.watch(mainHtmlSrc, ['copy']);
gulp.watch(fontsSrc, ['copy']);
gulp.watch(imagesSrc, ['copy']);
gulp.watch(extJsSrc, ['copy']);
gulp.watch(path.join(clientSourceFolder, 'scss', '**', '*'), ['sass']);
gulp.watch(jsToTranspile, ['babel']);
gulp.watch(templatesLocation, ['templates']);
});
gulp.task('clean', function () {
return del('dist/**/*', { force: true });
});
gulp.task('build:client', ['copy', 'sass', 'babel', 'templates']);
gulp.task('build', ['clean'], function () {
gulp.start('build:client');
});
gulp.task('build:watch', ['build'], function () {
gulp.start('watch:client');
});