我有一个svg2png的问题,我想把我的svg文件转换成png,它在gulp任务中说它是UnhandledPromiseRejectionWarning
var gulp = require('gulp'),
svgSprite = require('gulp-svg-sprite'),
rename = require('gulp-rename'),
del = require('del'),
svg2png = require('gulp-svg2png');
// var config consist of mode we used, and it used the css mode
var config = {
mode: {
css: {
sprite: 'sprite.svg',
render: {
css: {
template: './gulp/template/sprite.css'
}
}
}
}
}
gulp.task('beginClean', function() {
return del(['./app/temp/sprite', './app/assets/images/sprites']);
});
gulp.task('createSprite', ['beginClean'], function() {
return gulp.src('./app/assets/images/icons/**/*.svg')
.pipe(svgSprite(config))
.pipe(gulp.dest("./app/temp/sprite/"));
});
gulp.task('createPngCopy', ['createSprite'], function() {
return gulp.src('./app/temp/sprite/css/*.svg')
.pipe(svg2png())
.pipe(gulp.dest('./app/temp/sprite/css'));
});
gulp.task('copySpriteGraphic', ['createPngCopy'], function() {
return gulp.src('./app/temp/sprite/css/**/*.{svg,png}')
.pipe(gulp.dest('./app/assets/images/sprites'));
});
gulp.task('copySpriteCSS', ['createSprite'], function() {
return gulp.src('./app/temp/sprite/css/*.css')
.pipe(rename('_sprite.css'))
.pipe(gulp.dest('./app/assets/styles/modules'));
});
gulp.task('endClean', ['copySpriteGraphic', 'copySpriteCSS'], function() {
return del('./app/temp/sprite');
});
gulp.task('icons', ['beginClean', 'createSprite', 'createPngCopy', 'copySpriteGraphic', 'copySpriteCSS', 'endClean']);当我在我的命令行上运行它时,它会说
(node:8400) UnhandledPromiseRejectionWarning
(node:8400) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8400) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.发布于 2018-03-20 14:42:24
我想这是因为最后一行代码的原因。您还需要处理上一个任务的回调,以删除此警告。
gulp.task('icons', ['beginClean', 'createSprite', 'createPngCopy', 'copySpriteGraphic', 'copySpriteCSS', 'endClean'], function() {
return true;
});发布于 2019-02-09 09:48:22
首先,让我向您提供我正在使用Node = 8.12.0 Npm = 6.41 Gulp Local = 3.9.1 Gulp CLI = 2.0.1的包的版本
我使用的Svg2png版本是2.0.2,我的解决方案如下:卸载Svg2Png npm uninstall gulp-svg2png --save-dev,然后使用npm install gulp-svg2png@1.0.0 --save-dev安装
https://stackoverflow.com/questions/49377675
复制相似问题