-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
74 lines (63 loc) · 1.78 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
import gulp from 'gulp';
import browserSync from 'browser-sync';
import {deleteAsync, deleteSync} from 'del';
import dotenv from 'dotenv';
import sourcemaps from 'gulp-sourcemaps';
import dartSass from 'sass';
import gulpSass from 'gulp-sass';
const sass = gulpSass(dartSass);
import autoprefixer from 'gulp-autoprefixer';
import webpack from 'webpack-stream';
dotenv.config()
const clean = (done) => {
deleteSync(['assets/css','assets/js'])
done()
};
const serve = (done) => {
browserSync({
proxy: process.env.LOCAL_URL,
open: 'external',
ghostMode: false
})
done()
}
const stylesDev = () => gulp.src('src/css/index.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/css'))
.pipe(browserSync.reload({ stream: true }));
const stylesProd = (watch) => gulp.src('src/css/index.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest('assets/css'))
const scriptsDev = () => gulp.src('./src/js/index.js')
.pipe(webpack({
output: {
filename: 'app.js',
},
mode: 'development',
devtool: 'source-map'
}))
.pipe(gulp.dest('assets/js'));
const scriptsProd = () => gulp.src('./src/js/index.js')
.pipe(webpack({
output: {
filename: 'app.js',
},
mode: 'production'
}))
.pipe(gulp.dest('assets/js'));
const reload = (done) => {
browserSync.reload();
done();
}
const watch = () => {
gulp.watch('src/**/*.scss', stylesDev)
gulp.watch('src/**/*.js', gulp.series(scriptsDev, reload))
gulp.watch('site/**/*.php', reload)
}
const dev = gulp.series(clean, stylesDev, scriptsDev, serve, watch)
const build = gulp.series(clean, stylesProd, scriptsProd)
export { dev, build };