我的目标是创建一组文件和包,以便在我的团队中轻松分享。目前我在我的本地Mac 10.9.2上安装了GulpJs,它编译正确。但是,当我与我的两位同事共享我的设置时,他们运行gulp命令时出现错误:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:998:11)
at Process.ChildProcess._handle.onexit (child_process.js:789:34)
以下是我的package.json文件:
{
"name": "MyApp",
"version": "0.0.1",
"description": "Name build process for responsive development frameworks",
"author": "My Name",
"devDependencies": {
"gulp-util": "^2.2.14",
"gulp": "^3.6.2",
"gulp-compass": "^1.1.8",
"gulp-concat": "^2.2.0",
"gulp-uglify": "^0.2.1",
"gulp-livereload": "^1.2.0",
"tiny-lr": "0.0.5",
"gulp-jshint": "^1.5.3",
"gulp-minify-html": "^0.1.1",
"gulp-minify-css": "^0.3.0",
"image-min": "^0.4.5",
"gulp-imagemin": "^0.5.0",
"gulp-newer": "^0.3.0"
}
}
然后我将gulpfile.js设置为:
// include gulp
var gulp = require('gulp'),
gutil = require('gulp-util');
// include plug-ins
var compass = require('gulp-compass'),
jshint = require('gulp-jshint'),
imagemin = require('gulp-imagemin'),
newer = require('gulp-newer'),
minifyHTML = require('gulp-minify-html'),
minifyCSS = require('gulp-minify-css'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
reload = require('gulp-livereload'),
lr = require('tiny-lr'),
server = lr();
var paths = {
jsSrc: [
'./src/js/vendor/jquery.js',
'./src/js/vendor/fastclick.js',
'./src/js/vendor/foundation.js'
],
ieJsSrc: [
'./src/js/vendor/foundation-ie/jquery.js',
'./src/js/vendor/foundation-ie/jquery.foundation.buttons.js',
'./src/js/vendor/foundation-ie/jquery.foundation.clearing.js',
'./src/js/vendor/foundation-ie/jquery.foundation.forms.js',
'./src/js/vendor/foundation-ie/jquery.foundation.reveal.js',
'./src/js/vendor/foundation-ie/jquery.foundation.tabs.js',
'./src/js/vendor/foundation-ie/jquery.foundation.tooltips.js'
],
jsDst: './src/js',
jsBuild: './build/common/js',
imgSrc: './src/img/*',
imgDst: './build/common/img',
imgBgSrc: './src/img/bg/*',
imgPhotoSrc: './src/img/photos/*',
imgBgDst: './build/common/img/bg',
imgPhotoDst: './build/common/img/photos',
htmlSrc: './src/**/*.html',
htmlDst: './build',
scssSrc: [
'./src/_scss/utsw.scss',
'./src/_scss/utsw-ie.scss',
'./src/_scss/themes/**/*.scss'
],
scssDst: './src/common/css/',
cssMedSrc: './src/css/themes/root/*.css',
cssMedDst: './src/root/css/',
cssMedBuild: './build/root/css/',
cssEaSrc: './src/css/themes/sites/early-access/*.css',
cssEaDst: './src/sites/early-access/css',
cssEaBuild: './build/sites/early-access/css',
cssProSrc: './src/css/themes/profile/*.css',
cssProDst: './src/profile/css/',
cssProBuild: './build/profile/css/',
cssNetSrc: './src/css/themes/intranet/*.css',
cssNetDst: './src/intranet/css/',
cssNetBuild: './build/intranet/css/'
};
// JS hint task
gulp.task('jshint', function() {
return gulp.src(paths.jsSrc)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// minify new or changed HTML pages
gulp.task('html', function() {
return gulp.src(paths.htmlSrc)
.pipe(gulp.dest(paths.htmlDst));
});
// JS concat, strip debugging and minify
gulp.task('scripts', function() {
return gulp.src(paths.jsSrc)
.pipe(concat('vendor.min.js'))
.pipe(gulp.dest(paths.jsDst))
.pipe(uglify())
.pipe(gulp.dest(paths.jsBuild));
});
gulp.task('ieScripts', function() {
return gulp.src(paths.ieJsSrc)
.pipe(concat('ie-vendor.min.js'))
.pipe(gulp.dest(paths.jsDst))
.pipe(uglify())
.pipe(gulp.dest(paths.jsBuild));
});
// Minify any new images
gulp.task('images', function() {
return gulp.src(paths.imgSrc)
.pipe(newer(paths.imgDst))
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest(paths.imgDst));
});
// Minify any new images
gulp.task('bg', function() {
// Add the newer pipe to pass through newer images only
return gulp.src(paths.imgBgSrc)
.pipe(newer(paths.imgBgDst))
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest(paths.imgBgDst));
});
// Minify any new images
gulp.task('photos', function() {
// Add the newer pipe to pass through newer images only
return gulp.src(paths.imgPhotoSrc)
.pipe(newer(paths.imgPhotoDst))
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest(paths.imgPhotoDst));
});
gulp.task('compass', function() {
return gulp.src(paths.scssSrc)
.pipe(compass({
sass: './src/_scss',
css: './src/css',
image: './src/img'
}))
.on('error', function(err) {
// Would like to catch the error here
})
.pipe(gulp.dest('./src/temp'));
});
gulp.task('rootCSS', function() {
return gulp.src(paths.cssMedSrc)
.pipe(gulp.dest(paths.cssMedDst))
.pipe(minifyCSS())
.pipe(gulp.dest(paths.cssMedBuild));
});
gulp.task('eaCSS', function() {
return gulp.src(paths.cssEaSrc)
.pipe(gulp.dest(paths.cssEaDst))
.pipe(minifyCSS())
.pipe(gulp.dest(paths.cssEaBuild));
});
gulp.task('proCSS', function() {
return gulp.src(paths.cssProSrc)
.pipe(gulp.dest(paths.cssProDst))
.pipe(minifyCSS())
.pipe(gulp.dest(paths.cssProBuild));
});
gulp.task('netCSS', function() {
return gulp.src(paths.cssNetSrc)
.pipe(gulp.dest(paths.cssNetDst))
.pipe(minifyCSS())
.pipe(gulp.dest(paths.cssNetBuild));
});
// Rerun the task when a file changes
gulp.task('watch', function() {
var server = reload();
gulp.watch(paths.htmlSrc, ['html']);
gulp.watch(paths.jsSrc, ['scripts']);
gulp.watch(paths.ieJsSrc, ['ieScripts']);
gulp.watch(paths.imgSrc, ['images']);
gulp.watch(paths.imgBgSrc, ['bg']);
gulp.watch(paths.imgPhotoSrc, ['photos']);
gulp.watch(paths.scssSrc, ['compass']);
gulp.watch(paths.cssMedSrc, ['rootCSS']);
gulp.watch(paths.cssEaSrc, ['eaCSS']);
gulp.watch(paths.cssProSrc, ['proCSS']);
gulp.watch(paths.cssNetSrc, ['netCSS']);
gulp.watch(['./src/*.html', './src/js/', './src/css/*.css'], function(e) {
server.changed(e.path);
});
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', [
'html',
'scripts',
'ieScripts',
'images',
'bg',
'photos',
'compass',
'rootCSS',
'eaCSS',
'proCSS',
'netCSS',
'watch'
]);
关于如何使用相同的src和gulpfile.js设置同事的任何建议都会很棒。
答案 0 :(得分:-3)
尝试再次删除并安装imagemin和gulp-imagemin。