-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
61 lines (52 loc) · 1.52 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
const fs = require('fs');
const mkdirp = require('mkdirp');
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const sass = require('gulp-sass');
const browserify = require('browserify');
const babelify = require('babelify');
const browserSync = require('browser-sync').create();
gulp.task('dist', () => {
mkdirp('./dist');
});
gulp.task('html', () => {
return gulp.src('src/**/*.html')
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
gulp.task('images', () => {
return gulp.src('src/images/**/*')
.pipe(gulp.dest('dist/images'))
.pipe(browserSync.stream());
});
gulp.task('js', () => {
browserify('src/scripts/main.js')
.transform(babelify, {presets: ["es2015"]})
.bundle()
.pipe(fs.createWriteStream('dist/bundled.js'));
browserSync.reload();
});
gulp.task('sass', () => {
return gulp
.src('src/styles/main.scss')
.pipe(sass())
.pipe(postcss([autoprefixer({browsers: ['last 2 versions']})]))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
gulp.task('watch', ['html', 'js', 'sass', 'images'], () => {
gulp.watch('src/**/*.js', ['js'], browserSync.reload);
gulp.watch('src/**/*.html', ['html'], browserSync.reload);
gulp.watch('src/**/*.scss', ['sass']);
});
gulp.task('serve', ['dist', 'watch'], () => {
browserSync.init({
server: {
baseDir: 'dist'
}
});
});
gulp.task('default', ['serve']);