-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
71 lines (62 loc) · 1.87 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
'use strict'
let gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
cleanCSS = require('gulp-clean-css'),
htmlmin = require('gulp-htmlmin'),
webpack = require('webpack-stream'),
concat = require('gulp-concat'),
nodemon = require('gulp-nodemon')
gulp.task('min-sass', function() {
return gulp.src('src/css/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(concat('master.css'))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('public/css'))
})
gulp.task('sass', function() {
return gulp.src('src/css/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(concat('master.css'))
.pipe(rename({
suffix: '.min'
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/css'))
})
gulp.task('htmlminify', function() {
return gulp.src(['./src/views/*/*.html','./src/views/*.html'])
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./public/views'))
})
gulp.task('webpack', function(){
return gulp.src(['./src/js/**/*.js'])
.pipe(
webpack(require(__dirname + '/webpack.config.js'))
.on('error', (err) => {
if (err) console.log('--- Webpack error ---\n', err)
})
)
.pipe(rename('bundle.js'))
.pipe(gulp.dest('public/js'))
})
gulp.task('watch', function () {
gulp.watch("./src/views/**/*.html", ['htmlminify'])
gulp.watch('./src/js/**/*.js', ['webpack'])
gulp.watch('./src/css/*.scss', ['sass'])
})
gulp.task('start', function () {
nodemon({
script: 'server.js',
ext: 'js',
env: { 'NODE_ENV': 'development' }
})
})
gulp.task('build',['min-sass','htmlminify','webpack'])
gulp.task('develop', ['sass','htmlminify','webpack','watch','start'])