forked from huijing/blank-html5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
93 lines (85 loc) · 2.24 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
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var cssnano = require('gulp-cssnano');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var babel = require('gulp-babel');
/**
* Launch the Server
*/
gulp.task('browser-sync', ['sass', 'scripts'], function() {
browserSync.init({
server: "./",
port: 2314
});
});
/**
* Compile files from scss
*/
gulp.task('sass', function () {
return gulp.src('scss/styles.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gulp.dest('./'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('sass-prod', function () {
return gulp.src('scss/styles.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(cssnano())
.pipe(gulp.dest('./'))
.pipe(browserSync.reload({stream:true}))
});
/**
* Compile files from js
*/
gulp.task('scripts', function() {
return gulp.src(['js/*.js', 'js/custom.js'])
.pipe(babel({
presets: ['env']
}))
.pipe(concat('scripts.js'))
.pipe(gulp.dest('./'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('scripts-prod', function() {
return gulp.src(['js/*.js', 'js/custom.js'])
.pipe(babel({
presets: ['env']
}))
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(gulp.dest('./'))
.pipe(browserSync.reload({stream:true}))
});
/**
* Reload page when html changes
*/
gulp.task('html', function () {
browserSync.reload();
});
/**
* Watch scss files for changes & recompile
* Watch js files for changes & concatenate
* Watch html files, reload BrowserSync
*/
gulp.task('watch', function () {
gulp.watch(['scss/*.scss'], ['sass']);
gulp.watch(['js/*.js'], ['scripts']);
gulp.watch(['index.html'], ['html']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the scripts, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);
gulp.task('build', ['sass-prod', 'scripts-prod']);