-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
60 lines (56 loc) · 1.75 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
/** Define plugins */
var gulp = require('gulp');
var bs = require('browser-sync').create();
var $ = require('gulp-load-plugins')();
/** Process SASS files */
gulp.task('styles', function () {
return gulp.src('./src/scss/*.scss')
.pipe($.sourcemaps.init({loadMaps: true}))
.pipe($.sass({outputStyle: 'compressed'}))
.pipe($.autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe($.cleanCss({compatibility: 'ie8'}))
.on('error', $.util.log)
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./public/css'));
});
/** Process HTML files */
gulp.task('htmlmin', function() {
return gulp.src('./src/*.html')
.pipe($.sourcemaps.init({loadMaps: true}))
.pipe($.htmlmin({
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeTagWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyJS: true,
minifyCSS: true
}))
.on('error', $.util.log)
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./public'));
});
/** Serve and watch for changes in files */
gulp.task('serve', function() {
bs.init({
// proxy nodemon and show the site in port 3000
proxy: "http://localhost:8080",
files: "public/**/*.*",
port: 3000,
});
var appFiles = ['./public/*', './public/css/*'];
gulp.watch('./src/scss/*.scss', ['styles']);
gulp.watch('./src/*.html', ['htmlmin']);
// Use nodemon to monitor changes, recharge the node app & browser-sync
$.nodemon({
script: 'app.js',
ext: 'js html css',
env: { 'NODE_ENV': 'development', 'PORT': '8080' }
}).on('start', bs.reload);
});
gulp.task('default', ['styles', 'htmlmin', 'serve']);