通常在Gulp任务中看起来像这样:
gulp.task('my-task', function() {
return gulp.src(options.SCSS_SOURCE)
.pipe(sass({style:'nested'}))
.pipe(autoprefixer('last 10 version'))
.pipe(concat('style.css'))
.pipe(gulp.dest(options.SCSS_DEST));
});
Run Code Online (Sandbox Code Playgroud)
是否可以将命令行标志传递给gulp(这不是任务)并让它根据具体条件运行任务?例如
$ gulp my-task -a 1
Run Code Online (Sandbox Code Playgroud)
然后在我的gulpfile.js中:
gulp.task('my-task', function() {
if (a == 1) {
var source = options.SCSS_SOURCE;
} else {
var source = options.OTHER_SOURCE;
}
return gulp.src(source)
.pipe(sass({style:'nested'}))
.pipe(autoprefixer('last 10 version'))
.pipe(concat('style.css'))
.pipe(gulp.dest(options.SCSS_DEST));
});
Run Code Online (Sandbox Code Playgroud) 我有以下gulpfile.js,我正在通过命令行"gulp message"执行:
var gulp = require('gulp');
gulp.task('message', function() {
console.log("HTTP Server Started");
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
[14:14:41] Using gulpfile ~\Documents\node\first\gulpfile.js
[14:14:41] Starting 'message'...
HTTP Server Started
[14:14:41] The following tasks did not complete: message
[14:14:41] Did you forget to signal async completion?
Run Code Online (Sandbox Code Playgroud)
我在Windows 10系统上使用gulp 4.这是gulp --version的输出:
[14:15:15] CLI version 0.4.0
[14:15:15] Local version 4.0.0-alpha.2
Run Code Online (Sandbox Code Playgroud) 这是我的gulpfile:
// Modules & Plugins
var gulp = require('gulp');
var concat = require('gulp-concat');
var myth = require('gulp-myth');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var imagemin = require('gulp-imagemin');
// Styles Task
gulp.task('styles', function() {
return gulp.src('app/css/*.css')
.pipe(concat('all.css'))
.pipe(myth())
.pipe(gulp.dest('dist'));
});
// Scripts Task
gulp.task('scripts', function() {
return gulp.src('app/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('all.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
// Images Task
gulp.task('images', function() {
return gulp.src('app/img/*')
.pipe(imagemin())
.pipe(gulp.dest('dist/img'));
});
// Watch Task
gulp.task('watch', function() {
gulp.watch('app/css/*.css', 'styles');
gulp.watch('app/js/*.js', 'scripts');
gulp.watch('app/img/*', 'images');
});
// …Run Code Online (Sandbox Code Playgroud) 我在Gulpfile中有一些我想要运行的任务,要么让它们的输出替换或改变现有文件.例如,我想运行wiredep 并让代码替换内部的块index.html(与源文件相同)所以基本上我有以下内容:
gulp.task('bower', () => {
return gulp.src('app/index.html')
.pipe(wiredep())
.pipe(gulp.dest('app/index.html')) // Have wiredep operate on the source
})
Run Code Online (Sandbox Code Playgroud)
但这会产生EEXIST错误.
同样,我想运行该stylus命令,并将输出传递给已存在的文件(因为它以前运行过).
我有任何选择但del每次都要跑步吗?似乎Gulp应该能够轻松覆盖现有文件,但我无法想出一个简单的方法.
我在我的机器上安装了Gulp的项目.运行Gulp Watch时,如果我向文件夹添加新图像,我的gulp-imagemin会崩溃.我已在该文件夹上正确设置了所有权限(多次检查),并且该图像也具有正确的权限.
该过程抛出以下错误:
错误:命令失败:/ Users/robbert/Sites/wordpress_cyklo/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng -strip all -clobber -force -fix -o 2 -out/var/folders/kj/wydtr_t92hqgymv2d2v43pjw0000gr/T/9ab534f4-267f-46cb-b99f-372028e6ed5b/var/folders/kj/wydtr_t92hqgymv2d2v43pjw0000gr/T/eabb0414-f9db-4b6f-8242-4c8d25004e1d/Users/robbert/Sites/wordpress_cyklo/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin/vendor/optipng:/ Users/robbert/Sites/wordpress_cyklo/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin -optipng/node_modules/optipng-bin/vendor/optipng:无法执行二进制文件
每当我在文件夹上运行Gulp时,我都会得到同样的错误,除非我通过我的Vagrant VM运行它.我该如何解决?我的VM速度慢很多,所以我真的希望能够在我的主操作系统上运行Gulp.
编辑:这是图像的吞咽:
// ### Images
// `gulp images` - Run lossless compression on all the images.
gulp.task('images', function() {
return gulp.src(globs.images)
.pipe(imagemin({
progressive: true,
interlaced: true,
svgoPlugins: [{removeUnknownsAndDefaults: false}, {cleanupIDs: false}]
}))
.pipe(gulp.dest(path.dist + 'images'))
.pipe(browserSync.stream());
});
Run Code Online (Sandbox Code Playgroud) 我一直试图弄清楚如何使用Gulp为任何类型的文件添加一行文本.
比如添加:
@import 'plugins'
Run Code Online (Sandbox Code Playgroud)
到我的main.sass文件.
或者将CDN添加到index.html文件中.
我试过了:
gulp.task('inject-plugins', function(){
gulp.src('src/css/main.sass')
.pipe(inject.after('// Add Imports', '\n@import \'plugins\'\n'));
});
Run Code Online (Sandbox Code Playgroud)
没有快乐.知道如何才能实现这一目标吗?
我刚刚开始使用Browserify,gulp我遇到了使用的示例watchify.
我不明白的是,为什么不使用gulp.watch呢?和
之间有什么区别?watchifygulp.watch
我的问题源于我给出的共享库,没有重新编译库的选项.错误说明undefined reference to memcpy@GLIBC_2.14.
我机器上的GLIBC版本是2.12.我见过人们使用该线路在线完成的修复工作
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
Run Code Online (Sandbox Code Playgroud)
我做的修复是使用十六进制编辑器将2.14的引用更改为GLIBC_2.2.5.执行命令时readelf -V lib_name.so,输出更改为:
0x0060 Name: GLIBC_2.14 Flags: none Version 6
......
0x0080 Name: GLIBC_2.2.5 Flags: none Version 4
Run Code Online (Sandbox Code Playgroud)
至:
0x0060 Name: GLIBC_2.2.5 Flags: none Version 6
......
0x0080 Name: GLIBC_2.2.5 Flags: none Version 4
Run Code Online (Sandbox Code Playgroud)
这解决了我的错误.我想知道的是它会产生什么样的影响.我曾尝试研究的memcpy对比的memmove与memcpy的在GLIBC_2.14开始的变更,但我不太明白是怎么回事,什么原问题的memcpy了.我担心这个"修复",虽然它允许我的程序运行,以防memcpy正在做的事情表现不正常.为什么我在网上看到的所有修复程序都专门链接到2.2.5版本?
如果有人能给我一些关于这个主题的见解或提供一些相关信息的链接,我将不胜感激.
我是Gulp的新手.我有两个任务:
gulp.task('jadehtml', function() {
var YOUR_LOCALS = {};
gulp.src('source/jade/*.jade')
.pipe(jade({
locals: YOUR_LOCALS,
pretty: true
}))
.pipe(gulp.dest('build'))
});
// End Gulp Jade
// default task
// sass
gulp.task('sass', function () {
return gulp.src('source/scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('build/css'));
});
Run Code Online (Sandbox Code Playgroud)
现在他们在单独运行时工作得很好.但是当我使用gulp.watch()命令时,他们会给我一个错误.这是我的watch任务:
gulp.task('watch', function() {
gulp.watch('source/jade/*.jade', 'jadehtml');
gulp.watch('source/scss/*.scss', 'sass');
});
Run Code Online (Sandbox Code Playgroud)
这是错误:
这是我目前gulpfile.js的监视列表
// Gulp watchlist
gulp.task('watch', ['browserSync', 'sass'], function(){
gulp.watch('app/scss/**/*.scss', ['sass']);
gulp.watch('app/*.html').on('change', browserSync.reload);
gulp.watch('app/js/**/*.js').on('change', browserSync.reload);
//add more watchers here
});
Run Code Online (Sandbox Code Playgroud)
这很有效.
但是我关注的教程有一些不同之处:
gulp.task('watch', ['browserSync', 'sass'], function (){
gulp.watch('app/scss/**/*.scss', ['sass']);
// Reloads the browser whenever HTML or JS files change
gulp.watch('app/*.html', browserSync.reload);
gulp.watch('app/js/**/*.js', browserSync.reload);
});
Run Code Online (Sandbox Code Playgroud)
我需要.on('更改',browserSync.reload)吗?有用; 我只是好奇我的工作是不是很好的做法.谢谢!