-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.mjs
102 lines (86 loc) · 2.28 KB
/
gulpfile.mjs
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
import gulp from 'gulp';
import sassLib from 'sass';
import gulpSass from 'gulp-sass';
import sassLint from 'gulp-sass-lint';
import stylelint from 'gulp-stylelint';
import sourcemaps from 'gulp-sourcemaps';
import autoprefixer from 'gulp-autoprefixer';
import cleanCSS from 'gulp-clean-css';
import imagemin from 'gulp-imagemin';
import terser from 'gulp-terser';
import svgmin from 'gulp-svgmin';
import eslint from 'gulp-eslint';
import browserSyncModule from 'browser-sync';
const { create: createBrowserSync } = browserSyncModule;
const browserSync = createBrowserSync();
const sass = gulpSass(sassLib);
// Assets
function assets() {
return gulp.src('assets/img/*.{jpg,jpeg,png,gif,svg}')
.pipe(imagemin())
.pipe(gulp.dest('public/assets/img'));
}
function svg() {
return gulp.src('assets/img/*.svg')
.pipe(svgmin())
.pipe(gulp.dest('public/assets/img'));
}
// Styles
function styles() {
return gulp.src(['assets/sass/app.scss', 'assets/sass/admin.scss'])
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/assets/css'))
.pipe(browserSync.stream());
}
// Scripts
function scripts() {
return gulp.src('assets/js/**/*.js')
.pipe(terser())
.pipe(gulp.dest('public/assets/js'));
}
// Lint
function lintStyle() {
return gulp.src('assets/sass/**/*.scss')
.pipe(sassLint({
options: {
formatter: 'stylish',
'merge-default-rules': false
},
rules: {
}
}))
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
}
function lintScript() {
return gulp.src(['assets/js/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
// Watch
function watch() {
browserSync.init({
proxy: 'localhost:3000',
open: false,
});
gulp.watch('assets/sass/**/*.scss', styles);
gulp.watch('**/*.php').on('change', browserSync.reload);
gulp.watch('**/*.php').on('change', browserSync.reload);
gulp.watch('assets/sass/**/*.scss', lintStyle);
// gulp.watch('assets/js/**/*.js', lintScript);
}
export {
assets,
svg,
styles,
scripts,
lintStyle,
lintScript,
watch,
};
export default gulp.parallel(assets, svg, scripts, styles);