Answer the question
In order to leave comments, you need to log in
Error when running gulp.watch "SyntaxError: Identifier 'watch' has already been declared" how to fix?
Error when executing gulp command
const { gulp, series, parallel, src, dest, watch } = require("gulp");
const browserSync = require('browser-sync').create();
const phpMinify = require('@cedx/gulp-php-minify');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const less = require('gulp-less');
const minifyCSS = require('gulp-csso');
const concat = require('gulp-concat');
const del = require('del');
const dir = {
"src": {
php: './app/*.php',
html: './',
css: './app/src/less/**/*.less',
js: './app/src/js/**/*.js',
},
"dest": {
dest: './build/*',
php: './build/',
html: './',
css: './build/css/',
js: './build/js/',
}
}
function php() {
return src(dir.src.php, { read: false })
.pipe(phpMinify({ mode: 'fast' }))
.pipe(dest(dir.dest.php))
}
function css() {
return src(dir.src.css)
.pipe(less())
.pipe(autoprefixer())
.pipe(minifyCSS())
.pipe(dest(dir.dest.css))
.pipe(browserSync.stream())
}
function js() {
return src(dir.src.js, { sourcemaps: true })
.pipe(concat('app.min.js'))
.pipe(uglify())
.pipe(dest(dir.dest.js, { sourcemaps: true }))
.pipe(browserSync.stream())
}
function clean() {
return del(dir.dest.build);
}
function watch() {
browserSync.init({
server: {
baseDir: './app'
}
});
gulp.watch(dir.src.css, css)
gulp.watch(dir.src.js, js)
gulp.watch(dir.src.php).on('change', browserSync.reload);
}
exports.js = js;
exports.css = css;
exports.php = php;
exports.clean = clean;
exports.watch = watch;
exports.build = series(clean, parallel(css, js))
exports.default = series(build, watch);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question