-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
72 lines (61 loc) · 1.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
//=========================
// Dependencies
//=========================
// Core
var path = require('path');
// Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var gulpif = require('gulp-if');
var babel = require('gulp-babel');
var sass = require('gulp-sass');
var csso = require('gulp-csso');
var autoprefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
//=========================
// Configuration
//=========================
var cfg = require('./gulp.cfg.js');
//=========================
// Tasks
//=========================
gulp.task('js', () => {
var files = [];
cfg.js.input.files.forEach((file) => {
files.push(path.join(cfg.js.input.dir, file));
});
var stream =
gulp.src(files)
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/env']
}))
.on('error', console.error.bind(console))
.pipe(concat(cfg.js.output.file))
.pipe(gulpif(cfg.js.output.minify, uglify()))
.pipe(gulpif(cfg.js.output.sourceMap, sourcemaps.write()))
.pipe(gulp.dest(cfg.js.output.dir));
});
gulp.task('sass', () => {
gulp.src(path.join(cfg.sass.input.dir, cfg.sass.pattern))
.pipe(sourcemaps.init())
.pipe(sass())
.on('error', console.error.bind(console))
.pipe(autoprefixer({
overrideBrowserslist: cfg.sass.output.autoPrefixerBrowsers
}))
.pipe(gulpif(cfg.sass.output.minify, csso()))
.pipe(gulpif(cfg.sass.output.sourceMap, sourcemaps.write()))
.pipe(gulp.dest(cfg.sass.output.dir));
});
gulp.task('static', () => {
gulp.src(path.join(cfg.static.input, cfg.static.pattern))
.pipe(gulp.dest(cfg.static.output));
})
gulp.task('watch', function () {
gulp.watch(path.join(cfg.js.input.dir, cfg.js.pattern), ['js']);
gulp.watch(path.join(cfg.sass.input.dir, cfg.sass.pattern), ['sass']);
gulp.watch(path.join(cfg.static.input, cfg.static.pattern), ['static']);
})
gulp.task('default', [ 'js', 'sass', 'static' ]);