forked from Infinite-Studio/tuto-gulp-introduction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
106 lines (91 loc) · 2.52 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
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
// Tâche par défaut
gulp.task('default', ['serve']);
// Tâche de build
gulp.task('dist', ['copy', 'img', 'lint'], function(){
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('app/*.html')
.pipe($.useref.assets())
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.minifyCss())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'));
});
// Tâche de livraison
gulp.task('delivery', ['dist'], function(){
gulp.src('dist/**/*')
.pipe($.zip('tuto-gulp-introduction.zip'))
.pipe(gulp.dest('.'));
});
// Création des watchers
gulp.task('serve', ['server', 'scss'], function () {
// Watch .scss files
gulp.watch('app/scss/**/*.scss', ['scss']);
});
// Lance le serveur
gulp.task('server', function () {
gulp.src('app')
.pipe($.webserver({
livereload: true,
port: 8000
}));
var options = {
url: "http://localhost:8000",
app: "chrome"
};
gulp.src("app/index.html")
.pipe($.open("", options));
});
// Lance le serveur de prod
gulp.task('server:prod', function() {
gulp.src('dist')
.pipe($.webserver({
livereload: true,
port: 9000
}));
var options = {
url: "http://localhost:9000",
app: "chrome"
};
gulp.src("dist/index.html")
.pipe($.open("", options));
});
// Compile les SCSS
gulp.task('scss', function () {
return gulp.src('app/scss/app.scss')
.pipe($.plumber())
.pipe($.sass())
.pipe($.autoprefixer("last 1 version"))
.pipe(gulp.dest('app/css'));
});
// Optimisation des images
gulp.task('img', function(){
return gulp.src('app/img/**/*')
.pipe($.imagemin())
.pipe(gulp.dest('dist/img'));
});
// Détection des erreurs de codage JavaScript
gulp.task('lint', function() {
return gulp.src('app/js/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
// Clean du dossier dist
gulp.task('clean', function(){
return gulp.src('dist', {read: false})
.pipe($.clean());
});
// Copie des fichiers dans le répertoire dist
gulp.task('copy', ['clean'], function(){
return gulp.src([
'app/index.html'
], { base: './app' }).pipe(gulp.dest('dist'));
});