我的项目=编码网站,我正在使用gulp。现在,当运行gulp v4时,我使用cmd gulp手表来创建我的站点。但是我想知道cmd gulp是做什么用的,什么时候我应该使用gulp,什么时候我应该使用gulp watch?我尝试使用cmd to,但它给出了错误: Task never defined: default。我知道我应该运行exports.default,但是我想我还需要创建一个函数?希望你能帮我弄清楚我是要用大口还是大口的手表,要为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;发布于 2019-12-22 23:50:42
要运行gulp cmd,您需要定义默认导出。
exports.default = watch这对于定义一个你经常使用的任务是很方便的。
https://stackoverflow.com/questions/59445510
复制相似问题