-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
71 lines (59 loc) · 1.78 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'
const gulp = require('gulp');
const connect = require('gulp-connect');
const concat = require('gulp-concat');
const imageMin = require('gulp-imagemin');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
// MAJOR FUNCTIONS
/*
gulp.task = define the task
gulp.src = target the file to work with
gulp.dest = target the folder to input to
gulp.watch = watch all files for any changes
*/
// Test To Confirm Gulp's installed successfully
gulp.task('test', () => {
console.log('gulp is running fine!')
});
// Creates Live Server
gulp.task('connect', () => {
connect.server({port:8889})
});
// Copy HTML files to >> dist
gulp.task('statics', () => {
gulp.src('src/*.html')
.pipe(gulp.dest('dist'))
});
// Compile ES6 syntax to ES5 syntax
// Put all JavaScript files in a main.js files
// Create minify version of the main.js files
gulp.task('minify', () => {
gulp.src('src/js/*.js')
.pipe(babel({presets: ['env']}))
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/js'))
});
// Compile Sass To CSS
gulp.task('style', () => {
gulp.src('src/sass/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('dist/css'))
});
// Minify images that could be found in the image dir
gulp.task('optImage', () => {
gulp.src('src/images/*')
.pipe(imageMin())
.pipe(gulp.dest('dist/images'))
});
// Enable runing all task by runing "gulp"
gulp.task('default', ['test', 'statics', 'connect', 'minify', 'style', 'optImage','watch']);
// Watch Over All The Files For Changes (Auto)
gulp.task('watch', () => {
gulp.watch('src/*.html', ['statics']);
gulp.watch('src/js/*.js', ['minify']);
gulp.watch('src/images/*', ['imageMin']);
gulp.watch('src/sass/*.scss', ['sass']);
})