-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
137 lines (118 loc) · 2.94 KB
/
gulpfile.babel.js
File metadata and controls
137 lines (118 loc) · 2.94 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
// Dependencies
import { series, parallel, watch, src, dest } from 'gulp';
import connectPHP from 'gulp-connect-php';
import plumber from 'gulp-plumber';
import notify from 'gulp-notify';
import sass from 'gulp-sass';
import postcss from 'gulp-postcss';
import autoprefixer from 'autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import webpack from 'webpack';
import webpackStream from 'webpack-stream';
import webpackConfigDEV from './webpack.dev';
import webpackConfigPROD from './webpack.prod';
import { create as browserSyncCreate } from 'browser-sync';
// Settings
const browserSync = browserSyncCreate();
const browserSyncProxy = 'local-url.test';
const basePath = __dirname;
const nodePath = `${__dirname}/node_modules`;
const destPath = `${basePath}/dist`;
// TASKS
// =======================================================================
// Plumber
const plumberHandler = {
errorHandler: notify.onError({
title: 'Gulp Error',
message: '<%= error.message %>'
})
};
// Reload
function reload(done) {
browserSync.reload();
done();
}
// SCSS
function scss() {
return src(`${basePath}/scss/**/*.scss`)
.pipe(plumber(plumberHandler))
.pipe(sourcemaps.init())
.pipe(sass({
precision: 10,
includePaths: [nodePath]
}))
.pipe(sourcemaps.write())
.pipe(dest(destPath))
.pipe(browserSync.stream());
}
function scss_prod() {
return src(`${basePath}/scss/**/*.scss`)
.pipe(plumber(plumberHandler))
.pipe(sass({
precision: 10,
outputStyle: 'compressed',
includePaths: [nodePath]
}))
.pipe(postcss([
autoprefixer({ cascade: false })
]))
.pipe(dest(destPath));
}
// JS
function js() {
return src(`${basePath}/js/main.js`)
.pipe(plumber(plumberHandler))
.pipe(webpackStream(webpackConfigDEV, webpack))
.pipe(dest(destPath));
}
function js_prod() {
return src(`${basePath}/js/main.js`)
.pipe(plumber(plumberHandler))
.pipe(webpackStream(webpackConfigPROD, webpack))
.pipe(dest(destPath));
}
// Watch
function watch_files() {
watch(`${basePath}/scss/**/*.scss`, scss);
watch(`${basePath}/js/**/*.js`, series(js, reload));
watch(`${basePath}/**/*.twig`, reload);
watch(`${basePath}/**/*.php`, reload);
watch(`${basePath}/**/*.html`, reload);
}
// PHP
function php() {
connectPHP.server({
port: 8000,
open: false,
hostname: '127.0.0.1',
base: __dirname,
stdio: 'ignore'
}, () => {
browserSync.init({
ghostMode: false,
ui: false,
notify: false,
proxy: '127.0.0.1:8000'
});
});
}
// Proxy
function proxy() {
browserSync.init({
ghostMode: false,
ui: false,
notify: false,
proxy: browserSyncProxy
});
}
const proxy = parallel(proxy, watch_files);
const build = parallel(scss_prod, js_prod);
export {
scss,
scss_prod,
js,
js_prod,
proxy,
build
};
export default parallel(php, watch_files);