javascript JS - Gulp 4初始文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript JS - Gulp 4初始文件相关的知识,希望对你有一定的参考价值。
const browsersync = require("browser-sync");
const gulp = require("gulp");
const phpConnect = require('gulp-connect-php');
const concat = require("gulp-concat");
const sass = require('gulp-sass');
const del = require('del');
const browserSync = require("browser-sync").create();
//Php connect
function connectsync() {
phpConnect.server({
// a standalone PHP server that browsersync connects to via proxy
port: 8000,
keepalive: true,
base: "dist"
}, function (){
browsersync({
proxy: '127.0.0.1:8000'
});
});
}
// BrowserSync Reload
function browserSyncReload(done) {
browsersync.reload();
done();
}
function clean(){
return del(["dist/**", "dist/.*", "!dist"], { force: true });
}
function php(){
return gulp.src("./src/**/*.php").pipe(gulp.dest("./dist"));
}
function style(){
return gulp.src('./src/scss/**/*.scss')
.pipe(concat("styles.css"))
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./dist/css'))
.pipe(browserSync.stream());
}
function js(){
return gulp.src("./src/**/*.js")
.pipe(concat("scripts.js"))
.pipe(gulp.dest("./dist/js"));
}
// Watch files
function watchFiles() {
gulp.watch("src/**/*.php", gulp.series(php, browserSyncReload));
gulp.watch("src/**/*.scss", gulp.series(style, browserSyncReload));
gulp.watch("src/**/*.js", gulp.series(js, browserSyncReload));
}
const initialFiles = gulp.series(clean, php, style, js);
const watch = gulp.series(initialFiles, gulp.parallel([watchFiles, connectsync]));
exports.default = watch;
以上是关于javascript JS - Gulp 4初始文件的主要内容,如果未能解决你的问题,请参考以下文章
javascript Gulp#4.0:简单的gulpfile.js集合
gulp初体验
[译] Gulp 4 入门指南
javascript Gulp.js工作流程
JS(JavaScript)的初了解7(更新中···)
javascript Gulp文件优化js,css和图像