-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
127 lines (115 loc) · 3.06 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
const gulp = require("gulp");
const log = require('fancy-log');
const del = require('del');
const imagemin = require('gulp-imagemin');
const imageResize = require('gulp-image-resize');
global._SRC_PATH = 'exports/';
global._BUID_PATH = 'build/';
global._IMAGES_FORMATS = 'jpg,jpeg,svg,gif';
// Config
let config = {
mode: 'development'
};
// node env mode production/development
process.env.NODE_ENV = process.env.NODE_ENV || config.mode || 'production';
log.info('Starting task in mode : ' + process.env.NODE_ENV );
/**
* clean
*/
function clean(){
return del([
_BUID_PATH + '**/*.*'
]);
}
/**
* images
*/
function images(cb){
return gulp.src('./exports/assets/img/**/*.{' + _IMAGES_FORMATS + '}')
.pipe(imagemin([
imagemin.svgo({plugins: [{removeViewBox: true}]})
], {
verbose: true
}))
.pipe(imageResize({
width : 1200,
height : 1200,
crop : false,
upscale : false
}))
.pipe(gulp.dest(_BUID_PATH));
cb();
}
/**
* scripts
*
*/
function scripts(cb){
return gulp.src('./exports/**/*.js')
.pipe(gulp.dest(_BUID_PATH));
}
/**
* html
*
* https://www.npmjs.com/package/gulp-htmlmin
*/
let htmlmin = require('gulp-htmlmin');
function html(cb) {
return gulp.src('./exports/**/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(_BUID_PATH));
cb();
}
/**
* styles
*
* http://cssnext.io/postcss/#gulp-postcss
*
*/
let postcss = require("gulp-postcss");
//var partialImport = require("postcss-partial-import");
let cssnext = require("postcss-cssnext");
// http://putaindecode.io/fr/articles/css/preprocesseurs/cssnext/
function styles(cb) {
return gulp.src('./exports/**/*.css')
.pipe(postcss([
require("postcss-import")(),
// https://github.com/postcss/postcss-url
require("postcss-url")(),
require("postcss-cssnext")({
browsers: ["> 1%","last 2 versions"],
features: {
customProperties: {
// true: les var() sont conservée pour les navigateur les supportant et calculé en fallback
// 'computed' les var() sont calculées mais root est conservé
preserve: "computed"
}
}
}),
]))
.pipe(gulp.dest(_BUID_PATH));
cb();
}
// https://www.npmjs.com/package/browser-sync
// var browserSync = require('browser-sync').create();
// gulp.task('build', ['styles','images','scripts','html'], function(){
//
// browserSync.init({
// server: "./build"
// });
// gulp.watch('./exports/assets/img/**/*.{jpeg,jpg,png,svg}',['images']);
// gulp.watch('./exports/assets/**/*.{css,js}',['styles','scripts']);
// gulp.watch('./exports/**/*.html',['html']);
// });
//
// gulp.task('default', ['styles'], function(){
//
// gulp.watch('./exports/assets/**/*.css',['styles']);
// });
const build = gulp.series(clean, gulp.parallel(images,scripts,styles,html));
exports.scripts = scripts;
exports.html = html;
exports.styles = styles;
exports.images = images;
exports.build = build;
exports.default = build;