forked from Lucas-Alarcon/fac_gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·150 lines (134 loc) · 3.94 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//commande d'installation
/*
npm install
// pour souvenir
npm install --save-dev gulp gulp-regex-rename gulp-babel babel-core babel-preset-env gulp-sass gulp-sourcemaps gulp-autoprefixer gulp-notify gulp-plumber gulp-svg-sprite gulp-svgmin gulp-concat gulp-uglify
ou
npm i -D gulp gulp-regex-rename gulp-sass gulp-babel babel-core babel-preset-env gulp-sourcemaps gulp-autoprefixer gulp-notify gulp-plumber gulp-svg-sprite gulp-svgmin gulp-concat gulp-uglify
*/
//Requires
var gulp = require('gulp');
// Include plugins
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var notify = require("gulp-notify");
var plumber = require('gulp-plumber');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
const babel = require('gulp-babel');
var rename = require('gulp-regex-rename');
// Watcher
gulp.task('watch', function() {
gulp.watch(['./css/**/*.scss'], ['css'])
.on('change', function () {
notify("CSS -> SCSS ==> OK").write('');
});
gulp.watch(['./js/a_compresser/*.js'], ['concat_minif'])
.on('change', function () {
notify("JS (concat) ==> OK").write('');
});
gulp.watch(['./js/**/*es6.js'], ['js_babel'])
.on('change', function () {
notify("JS (babel) ==> OK").write('');
});
});
// tache CSS = compile vers mon_site.css et ajoute mon_site.css.map
gulp.task('css', function () {
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Problème!",
message: "Erreur CSS: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src('./css/mon_site.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded' // CSS non minifiée plus lisible ('}' à la ligne)
}))
.pipe(autoprefixer())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./css'));
});
// Concatener
gulp.task('concat_minif', function() {
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Problème!",
message: "Erreur JS: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src(['./js/a_compresser/*.js'])
.pipe(plumber({errorHandler: onError}))
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['env']
}))
.pipe(concat('mon_site.min.js', {newLine: ';'}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./js'));
});
gulp.task('js_babel', function() {
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Problème!",
message: "Erreur JS babel: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src(['js/**/*.es6.js'])
.pipe(plumber({errorHandler: onError}))
.pipe(babel({
presets: ['env']
}))
.pipe(rename(/\.es6/, ''))
.pipe(gulp.dest('./js'));
});
gulp.task('default', ['css', 'concat_minif']);
var svgSprite = require('gulp-svg-sprite');
//var plumber = require('gulp-plumber');
var baseDir = './svg'; // <-- Set to your SVG base directory
//var baseDir = 'svgmin'; // <-- Set to your SVG base directory
var svgGlob = '**/*.svg'; // <-- Glob to match your SVG files
var outDir = './img/'; // <-- Main output directory
var config = {
"shape": {
"spacing": {
"box": "icon"
}
},
"mode": {
/* "view": {
"dest": ".",
"sprite": "sprite_css_pictos.svg",
"bust": false
},
*/
"symbol": {
"dest": ".",
"sprite": "sprite_symbol_pictos.svg",
}
}
};
gulp.task('svgsprite', function() {
return gulp.src(svgGlob, {cwd: baseDir})
.pipe(plumber())
.pipe(svgSprite(config)).on('error', function(error){ console.log(error); })
.pipe(gulp.dest(outDir));
});
var svgmin = require('gulp-svgmin');
gulp.task('svgmin', function () {
return gulp.src('./svg/*.svg')
.pipe(svgmin())
.pipe(gulp.dest('./svgmin'));
});