-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
124 lines (110 loc) · 4.23 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cleanCss = require('gulp-clean-css');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const imagemin = require('gulp-imagemin');
const browserSync = require('browser-sync').create()
const nodemon = require('gulp-nodemon');
const mainBowerFiles = require('main-bower-files');
const sourcemaps = require('gulp-sourcemaps');
const reload = browserSync.reload;
var config = {
bootstrapDir: "./bower_components/bootstrap/",
fontawesomeDir: './bower_components/fontawesome/',
publicDir: './dist/public',
imgDir: './src/public/img',
videoDir: './src/public/video',
bowerDir: './bower_components'
}
gulp.task('bower', function () {
return gulp.src(mainBowerFiles(), {
base: "bower_components"
})
.pipe(gulp.dest(config.publicDir + "/lib"))
});
gulp.task('fonts', function () {
return gulp.src(config.fontawesomeDir + '/web-fonts-with-css/webfonts/**.*')
.pipe(gulp.dest(config.publicDir + '/webfonts'))
});
gulp.task('sass', function () {
return gulp.src('./src/public/sass/**/*.scss', config.bootstrapDir + '/scss')
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: [config.bootstrapDir + '/scss', config.fontawesomeDir + '/web-fonts-with-css/scss']
}).on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(config.publicDir + '/css'));
});
gulp.task('sassBuild', function () {
return gulp.src('./src/public/sass/**/*.scss', config.bootstrapDir + '/scss')
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: [config.bootstrapDir + '/scss', config.fontawesomeDir + '/web-fonts-with-css/scss']
}).on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(cleanCss({ compatibility: 'ie8' }))
.pipe(gulp.dest(config.publicDir + '/css'));
});
gulp.task('html', function () {
return gulp.src('./src/public/*.html')
.pipe(gulp.dest(config.publicDir))
})
gulp.task('js', function () {
return gulp.src(['./src/public/js/**/*.js'])
.pipe(concat('main.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(config.publicDir + '/js'))
})
gulp.task('jsBuild', function () {
return gulp.src(['./src/public/js/**/*.js'])
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest(config.publicDir + '/js'))
})
gulp.task('img', function () {
return gulp.src(config.imgDir + '/*')
.pipe(imagemin())
.pipe(gulp.dest(config.publicDir + '/img'))
})
gulp.task('video', function () {
return gulp.src(config.videoDir + '/*')
.pipe(gulp.dest(config.publicDir + '/video'))
})
gulp.task('nodemon', function (cb) {
var started = false;
return nodemon({
script: 'server.js',
ext: "js",
}).on('start', function () {
if (!started) {
cb();
started = true;
gulp.watch(config.bowerDir, gulp.parallel('bower')).on('change', reload);
gulp.watch('./src/public/js/*.*', gulp.parallel('js')).on('change', reload);
gulp.watch('./src/public/sass/*.*', gulp.parallel('sass')).on('change', reload);
gulp.watch('./src/public/img/*.*', gulp.parallel('img')).on('change', reload);
gulp.watch('./src/public/video/*.*', gulp.parallel('video')).on('change', reload);
gulp.watch('./src/public/*.html', gulp.parallel('html')).on('change', reload);
gulp.watch(config.fontawesomeDir + '/web-fonts-with-css/webfonts/**.*', gulp.parallel('fonts')).on('change', reload);
}
})
})
gulp.task('start', gulp.series('bower', 'video', 'fonts', 'sass', 'html', 'js', 'img', 'nodemon', function () {
browserSync.init({
proxy: "http://localhost:3000",
files: ['/dist/public/**/*.*'],
browser: "chrome",
port: 7000
})
}))
gulp.task('default', gulp.parallel('start'));
gulp.task('build', gulp.series('bower', 'video', 'fonts', 'sassBuild', 'html', 'jsBuild', 'img'));