forked from escueladigital/EDboilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
74 lines (66 loc) · 1.78 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
import gulp from 'gulp';
import plumber from 'gulp-plumber';
import pug from 'gulp-pug';
import browserSync from 'browser-sync';
import sass from 'gulp-sass';
import postcss from 'gulp-postcss';
import cssnano from 'cssnano';
import watch from 'gulp-watch';
import browserify from 'browserify';
import babelify from 'babelify';
import source from 'vinyl-source-stream';
import sourcemaps from 'gulp-sourcemaps';
import buffer from 'vinyl-buffer';
const server = browserSync.create();
const postcssPlugins = [
cssnano({
core: false,
autoprefixer: {
add: true,
browsers: '> 1%, last 2 versions, Firefox ESR, Opera 12.1'
}
})
];
const sassOptions = {
outputStyle: 'expanded'
};
gulp.task('styles', () =>
gulp.src('./dev/scss/styles.scss')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(plumber())
.pipe(sass(sassOptions))
.pipe(postcss(postcssPlugins))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./public/css'))
.pipe(server.stream({match: '**/*.css'}))
);
gulp.task('pug', () =>
gulp.src('./dev/pug/pages/*.pug')
.pipe(plumber())
.pipe(pug())
.pipe(gulp.dest('./public'))
);
gulp.task('scripts', () =>
browserify('./dev/js/index.js')
.transform(babelify)
.bundle()
.on('error', function(err){
console.error(err);
this.emit('end')
})
.pipe(source('scripts.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./public/js'))
);
gulp.task('default', () => {
server.init({
server: {
baseDir: './public'
},
});
watch('./dev/scss/**/*.scss', () => gulp.start('styles'));
watch('./dev/js/**/*.js', () => gulp.start('scripts',server.reload) );
watch('./dev/pug/**/*.pug', () => gulp.start('pug', server.reload) );
});