-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
137 lines (126 loc) · 3.16 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
const gulp = require("gulp");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");
const autoprefixer = require("gulp-autoprefixer");
const c = require("ansi-colors");
const notifier = require("node-notifier");
const rename = require("gulp-rename");
const wait = require("gulp-wait");
const csso = require("gulp-csso");
const browserSync = require("browser-sync").create();
const webpack = require("webpack");
const fileinclude = require("gulp-file-include");
const image = require("gulp-image");
const htmlmin = require('gulp-htmlmin');
sass.compiler = require("sass"); ////node-sass dla klasycznego
const showError = function (err) {
notifier.notify({
title: "Error in sass",
message: err.messageFormatted,
});
console.log(c.red("==============================="));
console.log(c.red(err.messageFormatted));
console.log(c.red("==============================="));
};
const server = (cb) => {
browserSync.init({
server: {
baseDir: "./dist",
},
notify: false,
//host: "192.168.0.24",
//port: 3000,
open: true,
//browser: "google chrome"
});
cb();
};
const images = function () {
return gulp
.src("./src/images/*")
.pipe(image())
.pipe(gulp.dest("./dist/images"));
};
const imagesSlider = function () {
return gulp
.src("./src/images/slider/*")
.pipe(image())
.pipe(gulp.dest("./dist/images/slider"));
};
const fonts = function () {
return gulp.src("./src/fonts/*").pipe(gulp.dest("./dist/fonts"));
};
const css = function () {
return gulp
.src("src/scss/style.scss")
.pipe(wait(500))
.pipe(sourcemaps.init())
.pipe(
sass({
outputStyle: "expanded",
}).on("error", showError)
)
.pipe(autoprefixer())
.pipe(
rename({
suffix: ".min",
basename: "style",
})
)
.pipe(csso())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist/css"))
.pipe(browserSync.stream());
};
const js = function (cb) {
//https://github.com/webpack/docs/wiki/usage-with-gulp#normal-compilation
return webpack(require("./webpack.config.js"), function (err, stats) {
if (err) throw err;
console.log(stats.toString());
browserSync.reload();
cb();
});
};
const html = function (cb) {
return gulp
.src(["src/html/*.html", "!src/html/inc/*.html"])
.pipe(
fileinclude({
prefix: "@@",
basepath: "@file",
})
)
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest("dist"))
};
const htmlReload = function (cb) {
browserSync.reload();
cb();
};
const watch = function () {
gulp.watch("src/scss/**/*.scss", { usePolling: true }, gulp.series(css));
gulp.watch("src/js/**/*.js", { usePolling: true }, gulp.series(js));
gulp.watch("src/images/*", { usePolling: true }, gulp.series(images));
gulp.watch(
"src/html/**/*.html",
{ usePolling: true },
gulp.series(html, htmlReload)
);
};
exports.default = gulp.series(
images,
fonts,
imagesSlider,
css,
html,
js,
server,
watch
);
exports.css = css;
exports.html = html;
exports.watch = watch;
exports.js = js;
exports.images = images;
exports.imagesSlider = imagesSlider;
exports.fonts = fonts;