运行 gulp.watch 或 gulp

Running gulp.watch or gulp

我的项目 = 编码网站,我正在使用 gulp。 现在,当 运行ning gulp v4 我正在使用创建我的网站的 cmd gulp 手表。 但我想知道 cmd gulp 是什么时候使用 gulp 什么时候使用 gulp watch? 我尝试使用 cmd gulp 但它给了我错误:任务从未定义:默认。 我知道我应该 运行 exports.default 但我想我还需要创建一个函数? 希望你能帮我弄清楚我是否需​​要使用 gulp 或 gulp 手表以及为 exports.default 写什么。 这是我的代码:)

const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
const autoprefixer = require('gulp-autoprefixer');



// complie scss to css

function style() {
    //1. ehere is the scss file
    return gulp.src('./scss/**/*.scss')
    //2. pass that file through sass compiler
        .pipe(sass().on('error', saas.logError))
    //3. where do I save the compled css?
        .pipe(gulp.dest('./css'))
    //4. stream changes to all browsers 
        .pipe(browserSync.stream())
    //5. fixes scaling
        .pipe(autoprefixer('last 3 versions'));
}

function watch() {
    browserSync.init({
        server: {
            baseDir: './'
        }
    });
    gulp.watch('./scss/**/*.scss', style);
    gulp.watch('./*index.html').on('change', browserSync.reload);
    gulp.watch('./js/**/*.js').on('change', browserSync.reload);
}

exports.style = style;
exports.watch = watch;

要运行 gulp cmd,您需要定义默认导出。

exports.default = watch

这对于定义您经常使用的任务很方便。