-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
81 lines (73 loc) · 2.43 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
var gulp = require('gulp'),
sass = require('gulp-sass')(require('sass')),
scsslint = require('gulp-scss-lint'),
postcss = require('gulp-postcss'),
criticalCss = require('gulp-critical-css'),
postcssCriticalCss = require('postcss-critical-css'),
cssnano = require('gulp-cssnano'),
autoprefixer = require('gulp-autoprefixer'),
cleanCss = require('gulp-clean-css'),
uglify = require('gulp-uglify'),
babel = require('gulp-babel'),
eslint = require('gulp-eslint'),
rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
notify = require('gulp-notify');
var sassFiles = 'assets/css/scss/**/*.scss',
cssFolder = 'assets/css/',
jsFolder = 'assets/js';
// Linting scss style to write better
gulp.task('scss-lint', function(){
return gulp.src(sassFiles)
.pipe(scsslint({
'config': 'lint.yml'
}));
});
//Compile scss files
gulp.task('styles', function(done){
return gulp.src(sassFiles)
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer]))
//.pipe(criticalCss())
.pipe(cleanCss({compatibility: 'ie10'}))
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(cssFolder))
.pipe(notify({message: 'sass compiled successfully'}))
});
//Critical css files
gulp.task('criticalCSS', function () {
var processors = [
postcssCriticalCss({
'outputPath': cssFolder,
'output': 'critical',
})
];
return gulp.src(sassFiles)
.pipe(postcss(processors))
});
//Es liting js to write better
gulp.task('es-lint', function(){
return gulp.src(['assets/js/*.js','!assets/js/*.min.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
//Minification javascript
gulp.task('minify-js', function () {
return gulp.src(['assets/js/*.js','!assets/js/*.min.js'])
.pipe(rename({ extname: '.min.js' }))
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(jsFolder))
.pipe(notify({message: 'js compiled successfully'}))
});
//Default task
gulp.task('default', function(){
gulp.watch(sassFiles, gulp.series('scss-lint','styles','criticalCSS'));
gulp.watch(['assets/js/*.js','!assets/js/*.min.js'], gulp.series('es-lint','minify-js'));
});