-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
139 lines (110 loc) · 3.2 KB
/
gulpfile.babel.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// VARIABLES
// npm packages
const gulp = require('gulp');
const args = require('yargs').argv;
const browserSync = require('browser-sync').create();
const autoprefixer = require('autoprefixer');
const cssnext = require('cssnext');
const del = require('del');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass');
// configuration file (requiere and execute)
const config = require('./gulp.config')();
// implicit plugins
const gulpcssnext = require('gulp-cssnext');
const gulpautoprefixer = require('gulp-autoprefixer');
// plugin loader (gulp-eslint, gulp-util, gulp-print, gulp-if)
const $ = require('gulp-load-plugins')({lazy: true});
// FUNCTIONS
const log = (msg) => {
if (typeof (msg) === 'object') {
for (const item in msg) {
if (msg.hasOwnProperty(item)) {
$.util.log($.util.colors.blue(msg[item]));
}
}
} else {
$.util.log($.util.colors.blue(msg));
}
};
const clean = (path, done) => {
log('Cleaning: ' + $.util.colors.blue(path));
del(path, done);
};
// TASKS
gulp.task('help', $.taskListing);
gulp.task('default', ['help']);
gulp.task('clean-styles', (done) => {
clean(config.stylesFolder + config.finalStyleFile, done);
});
gulp.task('clean-js', (done) => {
clean(config.jsFolder + config.finalJSFile, done);
});
gulp.task('styles', ['clean-styles'], () => {
log('Compiling Sass --> CSS');
return gulp
.src(config.styleFiles)
.pipe($.plumber())
.pipe(sass())
.pipe(concat(config.finalStyleFile))
.pipe($.autoprefixer(['last 2 version', '> 5%']))
.pipe(gulp.dest(config.stylesFolder))
.pipe(browserSync.stream());
});
gulp.task('js', ['clean-js'], () => {
log('Combining + uglifying');
return gulp
.src(config.jsFiles)
.pipe($.plumber())
.pipe(concat(config.finalJSFile))
.pipe(uglify())
.pipe(gulp.dest(config.jsFolder))
.pipe(browserSync.stream());
});
gulp.task('serve', ['styles'], () => {
log('Serving web application...');
browserSync.init({
server: './src/',
});
gulp.watch(config.stylesFolder + '**/*.scss', ['styles']);
gulp.watch(config.sourceFolder + '**/*.js', ['js']);
gulp.watch(config.sourceFolder + '**/*.html').on('change', browserSync.reload);
});
gulp.task('lint', () => {
log('Analyzing source code with ESLint');
return gulp
.src(config.alljs)
.pipe($.if(args.verbose, $.print()))
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failOnError());
});
// POSTCSS TEST TASKS
gulp.task('postcss', () => {
const processors = [
cssnext(),
autoprefixer({browsers: ['last 2 version']}),
];
log('Compiling styles with postcss');
return gulp
.src(config.css4)
.pipe($.postcss(processors))
.pipe(gulp.dest(config.temp));
});
gulp.task('plugins', () => {
log('Compiling styles with plugins');
return gulp
.src(config.css4)
.pipe(gulpcssnext())
.pipe(gulpautoprefixer({browsers: ['last 2 version']}))
.pipe(gulp.dest(config.temp));
});
gulp.task('lazy-plugins', () => {
log('Compiling styles with lazy plugins');
return gulp
.src(config.css4)
.pipe($.cssnext())
.pipe($.autoprefixer({browsers: ['last 2 version']}))
.pipe(gulp.dest(config.temp));
});