-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
151 lines (114 loc) · 3.19 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
151
require('dotenv').config();
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const concat = require('gulp-concat');
const babel = require('gulp-babel');
const svgmin = require('gulp-svgmin');
const browserSync = require('browser-sync').create();
const gulppath = require('./gulppath');
const isProductionEnviroment = process.env.NODE_ENV === 'production';
let tasksArr = [];
let taskObjectArr = Object.entries(gulppath.tasks);
for ( let key in taskObjectArr ) {
if ( taskObjectArr[key][1] !== null ) {
tasksArr.push(taskObjectArr[key][0]);
}
}
const optionsSourcemaps = isProductionEnviroment ? { sourcemaps: true } : null;
function ltco_styles() {
let { srcPath, destPath } = gulppath.tasks.ltco_styles;
return gulp
.src(srcPath)
.pipe(sass({
outputStyle: isProductionEnviroment ? 'compressed' : 'expanded' // expanded / nested / compact / compressed
}))
.pipe(autoprefixer())
.pipe(gulp.dest(destPath))
.pipe(browserSync.stream())
}
gulp.task('ltco_styles', ltco_styles);
function ltco_scripts() {
let { srcPath, destPath } = gulppath.tasks.ltco_scripts;
return gulp
.src(srcPath, optionsSourcemaps)
.pipe(babel())
.pipe(gulp.dest(destPath, optionsSourcemaps))
.pipe(browserSync.stream())
}
gulp.task('ltco_scripts', ltco_scripts);
function ltco_scripts_plugins() {
let { srcPath, destPath } = gulppath.tasks.ltco_scripts_plugins;
return gulp
.src(srcPath, optionsSourcemaps)
.pipe(concat('plugins.min.js'))
.pipe(gulp.dest(destPath, optionsSourcemaps))
.pipe(browserSync.stream())
}
gulp.task('ltco_scripts_plugins', ltco_scripts_plugins);
function ltco_svgs() {
let { srcPath, destPath } = gulppath.tasks.ltco_svgs;
return gulp
.src(srcPath)
.pipe(svgmin())
.pipe(gulp.dest(destPath))
.pipe(browserSync.stream())
}
gulp.task('ltco_svgs', ltco_svgs);
function ltco_html() {
let { srcPath, destPath } = gulppath.tasks.ltco_html;
return gulp
.src(srcPath)
.pipe(gulp.dest(destPath))
.pipe(browserSync.stream())
}
gulp.task('ltco_html', ltco_html);
function ltco_fonts() {
let { srcPath, destPath } = gulppath.tasks.ltco_fonts;
return gulp
.src(srcPath)
.pipe(gulp.dest(destPath))
.pipe(browserSync.stream())
}
gulp.task('ltco_fonts', ltco_fonts);
function browser() {
let browserSyncOptions = gulppath.browserSync;
const options = {
server: {
baseDir: './public',
serveStaticOptions: {
extensions: ['html']
}
}
};
browserSync.init(browserSyncOptions || options);
}
gulp.task('browser-sync', browser);
function watchLT() {
let watchPath = gulppath.watch;
gulp.watch(watchPath.ltco_styles, ltco_styles);
gulp.watch(watchPath.ltco_scripts, ltco_scripts);
gulp.watch(watchPath.ltco_svgs, ltco_svgs);
gulp.watch(watchPath.ltco_html, ltco_html);
}
gulp.task('watchLT', watchLT);
gulp.task(
'server',
gulp.series(
gulp.parallel(tasksArr),
gulp.parallel(
'watchLT',
'browser-sync'
)
)
);
gulp.task(
'dev',
gulp.series(
gulp.parallel(tasksArr),
gulp.parallel(
'watchLT'
)
)
);
gulp.task( 'default', gulp.parallel(tasksArr) );