-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
144 lines (132 loc) · 3.21 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
140
141
142
143
144
'use strict';
const OPTIONS = {
autoprefixer: {
browsers: ['> 1%', 'last 3 versions', 'Safari > 7']
},
browsersync: {
server: true,
ghostMode: {
clicks: true
},
browser: ['google chrome'],
reloadOnRestart: true,
injectChanges: true
},
cssnano: {
autoprefixer: false,
calc: {
mediaQueries: true
},
colormin: false,
convertValues: {
precision: 0
},
discardComments: {
removeAll: true
},
discardUnused: false,
mergeIdents: false,
reduceIdents: false,
svgo: {
encode: true
},
zindex: false
},
loadplugins: {
lazy: true
},
postcss: {
syntax: 'scss'
},
sass: {
outputStyle: 'expanded'
},
stylelint: {
reporters: [{
formatter: 'string',
console: true
}]
}
};
import gulp from 'gulp';
import del from 'del';
import postscss from 'postcss-scss';
import reporter from 'postcss-reporter';
const BROWSERSYNC = require('browser-sync').create();
const $ = require('gulp-load-plugins')(OPTIONS.loadplugins);
// Start a server
// -----------------------------------------------------------------------------
gulp.task('server', ['sass'], () => {
if (!BROWSERSYNC.active) {
BROWSERSYNC.init(OPTIONS.browsersync);
}
gulp.watch('./src/*.scss', ['sass']);
gulp.watch('./src/*.js', ['js']);
gulp.watch('./*.html').on('change', BROWSERSYNC.reload);
});
// Sass/CSS
// -----------------------------------------------------------------------------
// Delete compiled CSS
gulp.task('clean:css', () => {
del('./dist/clearmenu.min.css');
});
// Lint Sass/CSS
gulp.task('lint:sass', () => {
return gulp
.src('./src/*.scss')
.pipe($.stylelint(OPTIONS.stylelint));
});
// Compile Sass to CSS, and create a sourcemap
gulp.task('sass', ['clean:css'], () => {
return gulp
.src('./src/*.scss')
.pipe($.sourcemaps.init())
.pipe($.plumber())
.pipe($.sass(OPTIONS.sass)
.on('error', $.sass.logError))
.on('error', $.notify.onError('Error compiling Sass!'))
.pipe($.autoprefixer(OPTIONS.autoprefixer))
.pipe($.cssnano(OPTIONS.cssnano))
.pipe($.rename({
suffix: '.min',
extname: '.css'
}))
.pipe($.sourcemaps.write('/'))
.pipe($.plumber.stop())
.pipe(gulp.dest('./dist/'))
.pipe(BROWSERSYNC.stream());
});
// JS
// -----------------------------------------------------------------------------
// Delete the generated project JS file
gulp.task('clean:js', () => {
del('./dist/clearmenu.min.js');
});
// Lint JavaScript via ESLint
gulp.task('js:lint', () => {
return gulp
.src('./src/*.js')
.pipe($.plumber())
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failAfterError());
});
// Process the JavaScript and create a sourcemap
gulp.task('js', () => {
return gulp
.src('./src/*.js')
.pipe($.sourcemaps.init())
.pipe($.plumber())
.pipe($.uglify())
.pipe($.rename({
suffix: '.min',
extname: '.js'
}))
.pipe($.sourcemaps.write('/'))
.pipe($.plumber.stop())
.pipe(gulp.dest('./dist/'))
.pipe(BROWSERSYNC.stream());
});
// Default
// -----------------------------------------------------------------------------
gulp.task('default', ['sass', 'js', 'server']);