-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.cjs
202 lines (155 loc) · 4.57 KB
/
gulpfile.cjs
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const concat = require('gulp-concat');
const debug = require('gulp-debug');
const rename = require('gulp-rename');
const del = require('del');
const minifyCss = require('gulp-clean-css');
const terser = require('gulp-terser');
const argv = require('yargs').argv;
var buildDir = 'public/assets';
var assetsDir = 'resources/assets';
var scssFiles = [
assetsDir + '/scss/app.scss'
];
var setupScssFiles = [
assetsDir + '/setup/setup.scss'
];
var jsFiles = [
assetsDir + '/js/*.js',
assetsDir + '/js/**/*.js',
];
var vendorJsFiles = [
'node_modules/jquery/dist/jquery.js',
'node_modules/@popperjs/core/dist/umd/popper.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/moment/moment.js',
'node_modules/moment/locale/pt-br.js',
// ws
'node_modules/laravel-echo/dist/echo.iife.js',
'node_modules/pusher-js/dist/web/pusher.js',
];
var vendorCssFiles = [
'node_modules/animate.css/animate.css',
];
// ---------------------------------------------------------------------------------------------------
// Copy assets
function copyAssets(files, dest) {
return gulp.src(files, { cwd: assetsDir })
.pipe(gulp.dest(buildDir + '/' + dest));
}
function copyFonts() {
return copyAssets('fonts/**/*.woff2', 'fonts');
}
function copyImages() {
return copyAssets('img/**/*', 'img');
}
// ---------------------------------------------------------------------------------------------------
// Css
function cssTasks(files, outputName, env = 'dev') {
var obj = gulp.src(files)
.pipe(debug({ title: 'css-debug' }))
.pipe(concat(outputName + '.scss'))
.pipe(sass({
outputStyle: env == 'prod' ? 'compressed' : 'expanded'
}).on('error', sass.logError))
.pipe(rename(outputName + '.min.css'));
if (env == 'prod') {
obj.pipe(minifyCss({ compatibility: 'ie8' }));
}
return obj.pipe(gulp.dest(buildDir + '/css'));
}
function cssDev() {
return cssTasks(scssFiles, 'styles');
}
function cssProd() {
return cssTasks(scssFiles, getVersionedName('styles'), 'prod');
}
function setupCssDev() {
return cssTasks(setupScssFiles, 'setup');
};
function setupCssProd() {
return cssTasks(setupScssFiles, getVersionedName('setup'), 'prod');
}
function vendorCssDev() {
return cssTasks(vendorCssFiles, 'vendor');
}
function vendorCssProd() {
return cssTasks(vendorCssFiles, getVersionedName('vendor'), 'prod');
}
// ---------------------------------------------------------------------------------------------------
// Js
function jsTasks(files, outputName, env = 'dev') {
var obj = gulp.src(files)
.pipe(debug({ title: 'js-debug' }))
.pipe(concat(outputName + '.js'));
if (env == 'prod') {
obj = obj.pipe(terser({
output: { comments: false }
}));
}
return obj.pipe(rename(outputName + '.min.js'))
.pipe(gulp.dest(buildDir + '/js'));
}
function jsDev() {
return jsTasks(jsFiles, 'scripts');
}
function jsProd() {
return jsTasks(jsFiles, getVersionedName('scripts'), 'prod');
}
function vendorJsDev() {
return jsTasks(vendorJsFiles, 'vendor');
}
function vendorJsProd() {
return jsTasks(vendorJsFiles, getVersionedName('vendor'), 'prod');
}
// ---------------------------------------------------------------------------------------------------
// Função de versionamento
/**
* Obtem o nome do arquivo de saída versionado
* @param {*} name
* @returns
*/
function getVersionedName(name) {
if (argv.tag && argv.tag !== true) {
name = name + '-' + argv.tag;
}
return name;
}
// ---------------------------------------------------------------------------------------------------
// Tasks avulsas
/**
* Monitora a alteração e realiza a publicação dos arquivos
* @returns
*/
function watch() {
gulp.watch(assetsDir + '/scss/**/*.scss', cssDev);
gulp.watch(assetsDir + '/setup/**/*.scss', setupCssDev);
gulp.watch(assetsDir + '/fonts/**/*', copyFonts);
gulp.watch(assetsDir + '/img/**/*', copyImages);
gulp.watch(assetsDir + '/js/**/*.js', jsDev);
}
gulp.task('clean', function () {
return del([buildDir]);
});
gulp.task('build', gulp.series(
'clean',
cssProd,
setupCssProd,
jsProd,
vendorCssProd,
vendorJsProd,
copyImages,
copyFonts,
));
gulp.task('default', gulp.series(
'clean',
cssDev,
setupCssDev,
jsDev,
vendorCssDev,
vendorJsDev,
copyImages,
copyFonts,
));
gulp.task('watch', gulp.series('default', watch));