-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
105 lines (95 loc) · 2.4 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
"use strict";
// Load plugins
const autoprefixer = require("gulp-autoprefixer");
const browsersync = require("browser-sync").create();
const cleanCSS = require("gulp-clean-css");
const gulp = require("gulp");
const plumber = require("gulp-plumber");
const rename = require("gulp-rename");
const sass = require("gulp-sass");
const uglify = require("gulp-uglify-es").default;
const gulpif = require('gulp-if');
const lazypipe = require('lazypipe');
const sourcemaps = require("gulp-sourcemaps");
const concat = require('gulp-concat');
const babel = require('gulp-babel');
// BrowserSync
function browserSync(done) {
browsersync.init({
proxy: "http://drupal.szpitalstaszow.localhost"
});
done();
}
// BrowserSync reload
function browserSyncReload(done) {
browsersync.reload();
done();
}
// CSS task
function css() {
const productionCss = lazypipe()
.pipe(rename, {
suffix: ".min"
})
.pipe(cleanCSS)
.pipe(gulp.dest, "./css")
return gulp
.src('./src/scss/**/*.scss')
.pipe(plumber())
.pipe(sass({
outputStyle: "expanded",
includePaths: "./node_modules",
}))
.on("error", sass.logError)
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest("./css"))
.pipe(gulpif(process.env.NODE_ENV === 'production', productionCss()))
.pipe(browsersync.stream());
}
// JS task
function js() {
const productionJs = lazypipe()
.pipe(rename, {
suffix: '.min'
})
.pipe(sourcemaps.init)
.pipe(uglify)
.pipe(sourcemaps.write) // Inline source maps.
.pipe(gulp.dest, './js')
return gulp
.src([
'./src/js/**/*.js',
'./node_modules/bootstrap/dist/js/bootstrap.js'
])
.pipe(babel({
presets: [
[
'@babel/env',
{
modules: "umd"
}
]
]
}))
.pipe(gulp.dest('./js'))
.pipe(gulpif(process.env.NODE_ENV === 'production', productionJs()))
.pipe(browsersync.stream())
}
// Watch files
function watchFiles() {
gulp.watch("./scss/**/*", css);
gulp.watch(["./js/**/*", "!./js/**/*.min.js"], js);
gulp.watch("./**/*.html.twig", browserSyncReload);
}
// Define complex tasks
const build = gulp.parallel(css, js)
const watch = gulp.series(build, gulp.parallel(watchFiles, browserSync));
// Export tasks
exports.css = css;
exports.js = js;
exports.build = build;
exports.watch = watch;
exports.default = build;