-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
51 lines (47 loc) · 1.26 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
// Compile scss into css
function style() {
// 1. Where is my scss file
return (
gulp
.src('./src/scss/**/*.scss')
// 2. pass that file through sass compiler
.pipe(sass().on('error', sass.logError))
// 3. where we want to compile it to
.pipe(gulp.dest('./public/styles'))
// 4. stream changes to all browser
.pipe(browserSync.stream())
);
}
// scripts
var jsFiles = './src/js/**/*.js',
jsDest = './public/js';
function scripts() {
return gulp
.src(jsFiles)
.pipe(concat('scripts.js'))
.pipe(gulp.dest(jsDest))
.pipe(rename('scripts.min.js'))
.pipe(uglify())
.pipe(gulp.dest(jsDest));
}
function watch() {
browserSync.init({
server: {
baseDir: './',
},
});
gulp.watch('./src/scss/**/*.scss', style);
gulp.watch(jsFiles, scripts);
gulp.watch('./*.html').on('change', browserSync.reload);
gulp.watch('./public/js/*.js').on('change', browserSync.reload);
}
// What does this do
exports.style = style;
exports.scripts = scripts;
exports.watch = watch;