全局安装gulp,在当前项目安装gulp-connect
npm i gulp -g
npm i gulp-connect -D
gulpfile.js
const gulp = require('gulp');
const connect = require('gulp-connect');
const config = {
root: '',
port: 8080,
livereload: true,
}
gulp.task('server', () => {
connect.server(config)
})
gulp.task('html', function() {
return gulp.src('*.html').pipe(connect.reload());
});
gulp.task('watch', function() {
return gulp.watch('*', gulp.series('html'));
});
gulp.task('default', gulp.series(gulp.parallel('server', 'watch', 'html')))
执行
gulp