This repository has been archived by the owner on Oct 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
107 lines (85 loc) · 2.29 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
/*
This gulpfile :
- Minimify images
- Concat CSS files
- Add autoprefixers
- Minimify CSS files
- Concat JS files
*/
// Configurations
var config = {
'root': 'dist/',
'src' : 'src/',
'dist': 'dist/'
}
// Dependencies
var gulp = require( 'gulp' ),
css_nano = require( 'gulp-cssnano' ),
rename = require( 'gulp-rename' ),
plumber = require( 'gulp-plumber' ),
sass = require( 'gulp-sass' ),
autoprefixer = require( 'gulp-autoprefixer' ),
concat = require( 'gulp-concat' ),
imagemin = require( 'gulp-imagemin' ),
uglify = require( 'gulp-uglify' );
// Connect
gulp.task('connect', function() {
connect.server({
root: 'dist',
livereload: true
});
});
// PHP
gulp.task('php', () => {
return gulp.src( [
'./src/**/*.php'
] )
.pipe(gulp.dest('./dist/'));
})
// Images
gulp.task('img', () => {
return gulp.src( [
'./src/img/**/**'
] )
.pipe(imagemin())
.pipe(gulp.dest('./dist/img/'));
})
// Fonts
gulp.task('fonts', () => {
return gulp.src( [
'./src/fonts/**'
] )
.pipe(gulp.dest('./dist/fonts/'));
})
// Sass
gulp.task( 'sass', function()
{
return gulp.src( './src/scss/*.scss' ) // Get Sass files
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(rename(function (path) {
path.basename += '.min';
}))
.pipe(gulp.dest('./dist/css'))
} );
// JS task
gulp.task( 'js', function()
{
return gulp.src( ['./src/js/*.js'] ) // Get JS files
.pipe( concat( 'script.js' ) ) // Concat in one file
.pipe( uglify() ) // Minify them (problem with ES6)
.pipe( gulp.dest( './dist/js/' ) ); // Put it in folder
} );
// Watch task
gulp.task( 'watch', function()
{
gulp.watch( './src/scss/**/**', [ 'sass' ] );
gulp.watch( './src/js/**/**', [ 'js' ] );
gulp.watch( './src/**/*.php', [ 'php' ] );
gulp.watch( './src/img/**/**', [ 'img' ] );
gulp.watch( './src/fonts/**/**', [ 'fonts' ] );
} );
gulp.task( 'default', [ 'php', 'sass', 'js', 'img', 'fonts', 'watch' ] );