This repository has been archived by the owner on Aug 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
115 lines (103 loc) · 2.77 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
import del from 'del';
import gulp from 'gulp';
import imagemin from 'gulp-imagemin';
import sourcemaps from 'gulp-sourcemaps';
import postcss from 'gulp-postcss';
import postcssEasyImport from 'postcss-easy-import/index.js';
import tailwind from 'tailwindcss';
import nesting from 'tailwindcss/nesting/index.js';
import autoprefixer from 'autoprefixer';
import browserSync from 'browser-sync';
import webpack from 'webpack-stream';
const forProduction = process.env.NODE_ENV === 'production';
const baseUrl = 'http://k3-scaffold.test';
let postcssPlugins = [
postcssEasyImport(),
nesting(),
tailwind(),
autoprefixer(),
];
export function clean () {
return del([
'./html/public/assets/css/*',
'./html/public/assets/js/*',
'./html/public/assets/maps/*'
]);
}
function cleanImages () {
return del('./html/public/assets/images/*');
}
function imageMin () {
return gulp.src('./src/images/*')
.pipe(imagemin())
.pipe(gulp.dest('./html/public/assets/images'));
}
export const images = gulp.series(cleanImages, imageMin);
function css () {
return gulp.src([
'./src/css/main.css',
'./src/css/print.css'
])
.pipe(sourcemaps.init())
.pipe(postcss(postcssPlugins))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('./html/public/assets/css'))
.pipe(browserSync.stream({once: true}));
}
function js () {
const mode = forProduction ? 'production' : 'development';
return gulp.src([
'./src/js/*'
])
.pipe(webpack({
mode: mode,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
},
{
test: /\.css$/,
use: [
'css-loader'
]
}
],
},
entry: {
main: './src/js/main.js',
},
output: {
filename: '[name].js'
}
}))
.pipe(gulp.dest('./html/public/assets/js'))
.pipe(browserSync.stream());
}
function watch () {
browserSync.init({
proxy: {
target: baseUrl,
proxyReq: [
function (req) {
req.setHeader('Access-Control-Allow-Origin', '*');
}
]
},
open: false
});
gulp.watch([
'./tailwind.config.js',
'./src/css/**/*',
'./html/site/**/*.php',
], {usePolling: true}, css);
gulp.watch('./src/js/**/*', {usePolling: true}, js);
gulp.watch([
'./html/site/**/*.yml',
], {usePolling: true}).on('change', browserSync.reload);
}
export const build = gulp.series(gulp.parallel(clean, images), gulp.parallel(css,js));
export const serve = gulp.series(gulp.parallel(css,js), watch)
export default serve;