我正在运行Lynda.com的教程,我正在尝试运行gulpfile,语法很好,但我无法理解终端的错误。
有人可以帮我提供帮助吗?
非常感谢!
gulpfile.js
var themename = 'pistol4';
var gulp = require('gulp'),
autoprefixer = require('autoprefixer'),
browserSync = require('browser-sync').create(),
image = require(gulp - image),
jshint = require('gulp-jshint'),
postcss = require('gulp-postcss'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
//Only work with new or updated files
newer = require('gulp-newer'),
//Name of working theme folder
root = '../' + themename + '/',
scss = root + 'sass/',
js = root + 'js/',
img = root + 'images/',
languages = root + 'languages';
// CSS via Sass and Autoprefixer
gulp.task('css', function () {
return gulp.src(scss + '(style.css,rtl.scss)')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded',
indentType: 'tab',
indentWidth: '1'
}).on('error', sass.logError))
.pipe(postcss([
autoprefixer('last 2 versions', '> 1%')
]))
.pipe(sourcemaps.write(scss + 'maps'))
.pipe(gulp.dest(root));
});
//Optimize images trough gulp-image
gulp.task('images', function() {
return gulp.src(img + 'RAW/**/*.(jpg,JPG,png)')
.pipe(newer(img))
.pipe(image())
.pipe(gulp.dest(img));
});
//Javascript
gulp.task('javascript', function() {
return gulp.src([js + '*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gulp.dest(js));
});
//Watch everything
gulp.task('watch', function() {
browserSync.init({
open: 'external',
proxy: 'pistol.dev',
port: '8080'
});
gulp.watch([root + '**/*.css', root + '**/*.scss'], ['css']);
gulp.watch(js + '**/*.js', ['javascript']);
gulp.watch(img + 'RAW/**/*.{jpg,JPG,png}', ['images']);
gulp.watch(root + '**/*').on('change', browserSync.reload);
});
//Default task (runs at initiation: gulp --verbose)
gulp.task('default', ['watch']);
来自终端的错误日志:
assert.js:81
throw new assert.AssertionError({
^
AssertionError: missing path
at Module.require (module.js:495:3)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\xampp\htdocs\pistol01.06.17\wp-
content\themes\gulp-dev\gulpfile.js:7:10)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
答案 0 :(得分:0)
这一行:image = require(gulp - image),
不会像@Juan说的那样工作。你的意思是:image = require('gulp-image'),
?
下一个错误:
“[BS]无法打开浏览器(如果您正在使用BrowserSync) 无头环境,您可能希望将open选项设置为false) “
由于我从未使用过浏览器同步功能,因此我可以猜测并编写通过Google搜索功能找到的内容。
我有两点建议:
browserSync.init({open: 'external',
to:browserSync.init({open: 'false',
简而言之就是做错误所说的。'--browser "chrome.exe"'
请告诉我们您是如何修理的,或者是否有任何帮助。