获取:SyntaxError: missing ) 在参数列表之后但无法找出 hulpfile.js 有什么问题 [英] Getting: SyntaxError: missing ) after argument list but can't find out whats wrong with hulpfile.js
问题描述
您好,使用以下 gulp 文件启动gulp default"时出现错误.我无法弄清楚文件有什么问题.
Hi I'm getting an error starting 'gulp default' with the following gulp file. I cannot figure out whats wrong with the file.
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var input = './scss/**/*.scss';
var output = './css';
gulp.task('sass', function() {
return gulp.src(input)
.pipe(sourcemaps.init())
.pipe(sass(errLogToConsole: true, outputStyle: 'compressed'))
.pipe(autoprefixer(browsers: ['last 2 versions', '> 5%', 'Firefox ESR']))
.pipe(sourcemaps.write())
.pipe(gulp.dest(output))
.pipe(browserSync.stream());
});
// Watch files for change and set Browser Sync
gulp.task('watch', function() {
// BrowserSync settings
browserSync.init({
proxy: "mydomain.loc",
files: "./css/styles.css"
});
// Scss file watcher
gulp.watch(input, ['sass'])
.on('change', function(event) {
console.log('File' + event.path + ' was ' + event.type + ', running tasks...')
});
});
// Default task
gulp.task('default', ['sass', 'watch']);
我已经重新安装了node,但是所有的包都不能解决问题.
I've allready reinstalled node and all the package won't solve the problem though.
推荐答案
参见 Gulp Sass with errLogToConsole: true 仍然停止我的其他监视任务 和 Gulp 生成的源映射在 Chrome 中不起作用.
不要使用 errLogToConsole,它似乎不再受支持.
Don't use errLogToConsole it doesn't appear to be supported anymore.
.pipe(sass(errLogToConsole: true, outputStyle: 'compressed'))
改成
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
如 gulp-sass 选项. 您之前的错误可能是由于不将您的选项包含在 {} 大括号中(它是一个对象).
as in gulp-sass options. Your earlier error was probably due to not including your options in {} braces (it is an object).
:
你的另一个错误是一样的
And your other error is the same
.pipe(autoprefixer(browsers: ['last 2 versions', '> 5%', 'Firefox ESR']))
应该是
.pipe(autoprefixer( { browsers: ['last 2 versions', '> 5%', 'Firefox ESR'] } ))
注意花括号.通常 gulp 插件的选项是 objects,因此它们需要用大括号 {} 包裹起来.
Note the curly braces. Usually the options to gulp plugins are objects so they need to be wrapped in braces {}.
这篇关于获取:SyntaxError: missing ) 在参数列表之后但无法找出 hulpfile.js 有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!