-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
161 lines (140 loc) · 3.79 KB
/
Copy pathgulpfile.babel.js
File metadata and controls
161 lines (140 loc) · 3.79 KB
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
151
152
153
154
155
156
157
158
159
160
161
'use strict';
/**
* Import gulp modules:
*/
import gulp from 'gulp';
import babel from 'gulp-babel';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import rename from 'gulp-rename';
import postcss from 'gulp-postcss';
import autoprefixer from 'gulp-autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import pug from 'gulp-pug';
import svg from 'gulp-svgo';
import imagemin from 'gulp-imagemin';
import fontcustom from 'gulp-fontcustom';
import clean from 'gulp-clean';
import base64 from 'gulp-base64';
import data from 'gulp-data';
/**
* Import modules:
*/
import path from 'path';
// import cssnext from 'postcss-cssnext';
// import precss from 'precss';
import sass from 'gulp-sass';
import mqpacker from 'css-mqpacker';
import cssnano from 'cssnano';
import atImport from 'postcss-import-url';
import browserSync from 'browser-sync';
// import getcolor from 'postcss-get-color';
/**
* Initial Properties
*/
const dirs = {
src: 'dev',
dest: 'public'
};
const reload = browserSync.reload;
const processors = [
atImport(),
// getcolor(),
mqpacker(),
cssnano({
reduceIdents: false,
})
];
/**
* gulp:tasks
*/
gulp.task('styles', () => {
return gulp.src(`${dirs.src}/sass/*.scss`)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 6 versions', 'ie 8']
}))
// .pipe(base64({
// extensions: ['svg'],
// maxImageSize: 8*1024, // bytes
// exclude: ['woff', 'woff2', 'ttf']
// }))
.pipe(postcss(processors))
// .pipe(importCss())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${dirs.dest}/assets/css/`))
});
gulp.task('babel', ['copyLibs'], () => {
return gulp.src([`${dirs.src}/js/**/*.+(js|es6)`, `!${dirs.src}/js/lib/*.js`])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify())
// .pipe(concat('app.js', {newLine: ';'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${dirs.dest}/assets/js/`));
});
gulp.task('copyLibs', () => {
return gulp.src([`${dirs.src}/js/lib/*.js`])
.pipe(gulp.dest(`${dirs.dest}/assets/js/lib/`));
});
gulp.task('images', ['svgs'], () => {
return gulp.src(`${dirs.src}/img/**/*.+(jpg|png|jpeg)`)
.pipe(imagemin())
.pipe(gulp.dest(`${dirs.dest}/assets/img`));
});
gulp.task('svgs', () => {
return gulp.src([`${dirs.src}/img/**/*.svg`])
.pipe(svg({
removeTitle: true,
}))
.pipe(gulp.dest(`${dirs.dest}/assets/img/`));
});
gulp.task('fonts', () => {
return gulp.src([`${dirs.src}/fonts/**/*`])
.pipe(gulp.dest(`${dirs.dest}/assets/fonts/`));
});
// gulp.task('icons', ['minify-css_fonts'], () => {
// return gulp.src(`${dirs.src}/img/icons/*.svg`)
// .pipe(fontcustom({
// 'config' : __dirname + "/icons.yml",
// }))
// .pipe(gulp.dest(`${dirs.dest}/assets/fonts/icons/`));
// });
// gulp.task('minify-css_fonts', () => {
// return gulp.src(`${dirs.dest}/assets/fonts/icons/*.css`)
// .pipe(postcss(processors))
// .pipe(gulp.dest(`${dirs.dest}/assets/fonts/icons`));
// });
gulp.task('views', () => {
return gulp.src(`${dirs.src}/pug/*.+(pug)`)
// .pipe(data(function(file) {
// return require(`./${dirs.src}/pug/json/data.json`);
// }))
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest(`${dirs.dest}`));
});
gulp.task('watch', () => {
gulp.watch(`${dirs.src}/pug/**/*.+(html|pug|json)`, ['views', reload]);
gulp.watch(`${dirs.src}/sass/**/*.scss`, ['styles', reload]);
gulp.watch(`${dirs.src}/img/**/*.+(jpg|jpeg|svg|png)`, ['images']);
gulp.watch(`${dirs.src}/js/**/*.+(js|es6)`, ['babel', reload]);
});
gulp.task('sync', () => {
browserSync({
server: {
baseDir: "./"
},
notify: false,
port: 9991
});
});
/**
* Register Tasks:
*/
gulp.task('default', ['styles', 'babel', 'views', 'images', 'sync', 'watch', 'fonts']);
gulp.task('production', ['styles', 'babel', 'views', 'images', 'fonts']);