首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行gulp.watch或gulp

运行gulp.watch或gulp
EN

Stack Overflow用户
提问于 2019-12-22 23:23:14
回答 1查看 52关注 0票数 0

我的项目=编码网站,我正在使用gulp。现在,当运行gulp v4时,我使用cmd gulp手表来创建我的站点。但是我想知道cmd gulp是做什么用的,什么时候我应该使用gulp,什么时候我应该使用gulp watch?我尝试使用cmd to,但它给出了错误: Task never defined: default。我知道我应该运行exports.default,但是我想我还需要创建一个函数?希望你能帮我弄清楚我是要用大口还是大口的手表,要为exports.default写些什么。下面是我的代码:)

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-22 23:50:42

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

代码语言:javascript
复制
exports.default = watch

这对于定义一个你经常使用的任务是很方便的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59445510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档