-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
44 lines (37 loc) · 1.18 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
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const { exec } = require('child_process');
// Define the source files to watch
const srcFiles = 'src/**/*.{js,jsx,ts,tsx,css,scss}';
// Get the site URL from an environment variable or use a default
const siteUrl = process.env.WP_SITE_URL || 'http://localhost:10003';
// Development server task
gulp.task('serve', function(done) {
browserSync.init({
proxy: `${siteUrl}?react-rooter=hot`,
port: 8888,
open: true,
notify: false
});
// Watch source files and reload on changes
gulp.watch(srcFiles, gulp.series('reload'));
// Run wp-scripts start
const wpScripts = exec('wp-scripts start', { stdio: 'inherit' });
wpScripts.stdout.on('data', (data) => {
console.log(data);
});
wpScripts.stderr.on('data', (data) => {
console.error(data);
});
wpScripts.on('close', (code) => {
console.log(`wp-scripts process exited with code ${code}`);
done();
});
});
// Reload task
gulp.task('reload', function(done) {
browserSync.reload();
done();
});
// Hot start task
gulp.task('hot-start', gulp.series('serve'));