-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
99 lines (78 loc) · 2.78 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
95
96
97
98
99
var gulp = require('gulp'),
browserify = require('browserify'),
babelify = require('babelify'),
source = require('vinyl-source-stream'),
gutil = require('gulp-util');
cssnano = require('gulp-cssnano'),
autoprefixer = require('gulp-autoprefixer'),
sass = require('gulp-ruby-sass'),
notify = require('gulp-notify'),
eslint = require('gulp-eslint'),
sourcemaps = require('gulp-sourcemaps'),
bs = require('browser-sync').create();
gulp.task('browser-sync', ['sass'], function() {
bs.init({
server: {
baseDir: "./"
}
});
});
gulp.task('sass', function () {
return sass('src/scss/styles.scss', { sourcemap: true })
.on('error', sass.logError)
.pipe(autoprefixer({
browsers: ["last 4 versions", "Firefox >= 27", "Blackberry >= 7", "IE 8", "IE 9"],
cascade: false
}))
.pipe(cssnano())
// For inline sourcemaps
.pipe(sourcemaps.write())
// For file sourcemaps
.pipe(sourcemaps.write('maps', {
includeContent: false,
sourceRoot: 'src/scss'
}))
.on('error', function(e) {
console.log(e);
})
.pipe(gulp.dest("css"))
.pipe(bs.reload({stream: true}))
.pipe(notify("SASS compilation complete: <%=file.relative%>"))
});
gulp.task('lint', () => {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src(['./src/js/**/*.js'])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint({configFile: 'eslint.json'}))
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
gulp.task('es6', function() {
browserify({
entries: './src/js/scripts.js',
debug: true,
transform: [babelify.configure({
presets: ['es2015']
})]
})
.transform(babelify)
.on('error',gutil.log)
.bundle()
.on('error',gutil.log)
.pipe(source('scripts.js'))
.pipe(gulp.dest('js'));
});
gulp.task('watch',function() {
gulp.watch('./src/js/**/*.js',{debounceDelay: 5000},['lint', 'es6'])
gulp.watch("src/scss/**/*.scss", ['sass'])
gulp.watch("*.html").on('change', bs.reload)
});
gulp.task('default', ['lint', 'es6', 'sass', 'browser-sync', 'watch']);