-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
94 lines (77 loc) · 2.45 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
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const rs = require('run-sequence');
const rename = require('gulp-rename');
const ts = require('gulp-typescript');
const sass = require('gulp-sass');
const tsProject = ts.createProject('tsconfig.json');
const DIR_CSS = './css/';
const DIR_SCSS_WATCH = './scss/**/*.scss';
const DIR_TS_WATCH = './ts/**/*.ts';
const DIR_JS_SRC = './js/src/';
const SASS_FILES = [
'./scss/base/*.scss',
'./scss/components/*.scss',
'./scss/layout/*.scss'
];
/**Default task (runs when executing `gulp` comand in the console)*/
gulp.task('default', () => {
gulp.watch(DIR_TS_WATCH, ['compile:ts']);
gulp.watch(DIR_SCSS_WATCH, ['sass']);
});
// the watch for sass files
gulp.task('sass:watch', () => {
gulp.watch(DIR_SCSS_WATCH, ['sass']);
});
// the task for sass compiler
gulp.task('sass', () => {
rs('create:components', 'compile:level', 'minify:level');
});
gulp.task('create:components', () => {
return gulp.src(SASS_FILES)
.pipe(sass({
outputStyle: 'compressed',
sourceComments: false
}).on('error', sass.logError))
.pipe(gulp.dest(DIR_CSS));
});
gulp.task('compile:level', () => {
return gulp.src('./scss/level.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(DIR_CSS));
});
gulp.task('minify:level', () => {
return gulp.src(DIR_CSS + 'level.css')
.pipe(sass({
outputStyle: 'compressed',
sourceComments: false
}).on('error', sass.logError))
.pipe(rename('level.min.css'))
.pipe(gulp.dest(DIR_CSS));
});
// the task compile sequence to typescript
gulp.task('compile:ts', () => {
rs('compiled', 'concat', 'minify');
});
/** compile all files.ts */
gulp.task('compiled', function() {
let tsResult = gulp.src(DIR_TS_WATCH)
.pipe(tsProject());
return tsResult.js.pipe(gulp.dest(DIR_JS_SRC));
});
/** the concatenation files in level.js */
gulp.task('concat', () => {
return gulp.src(DIR_JS_SRC + '*.js')
.pipe(concat('level.js'))
.pipe(gulp.dest('./js/'));
});
/**Minifies level.js*/
gulp.task('minify', () => {
return gulp.src('./js/level.js')
.pipe(uglify({ compress: { drop_console: true }, mangle: false }).on('error', function(e) {
console.log('Error uglify: ' + e);
}))
.pipe(rename('level.min.js'))
.pipe(gulp.dest('./js/'));
});