2016-08-04 2 views
1

에서 제거 .svg 때 이명 령에서 .png를 생성 :꿀꺽 : 삭제 나는 src 폴더에 .PNG .svg 파일에 대한 폴백을 만드는 꿀꺽 작업이 SRC

gulp.task('svg2png', ['svg'], function() { 
    return gulp.src(src + '/svg/**/*.svg') 
    .pipe(plugins.newer(dest + '/svg')) 
    .pipe(plugins.svg2png()) 
    .pipe(gulp.dest(dest + '/svg')) 
    .pipe(plugins.notify({ 
    message: 'svg2png task complete', onLast: true 
    })); 
}); 

합니다 (svg 작업이 svgmin입니다)

나는 다음과 같이 시계의 작업을 확장합니다 (이명 령 폴더) 생성 된 파일을 삭제하여 자신의 뒤에 정돈하고 생각하고 싶었 :

gulp.task('watch', function() { 
    var watchSvg = gulp.watch('src/svg/**/*.svg', ['svg2png']); 

    watchSvg.on('change', function(event) { 
    if (event.type === 'deleted') { 
     var filePathFromSrc = path.relative(path.resolve('src'), event.path); 
     var destFilePath = path.resolve('dist', filePathFromSrc); 
     del.sync(destFilePath); 
    } 
    }); 
}); 

이것은 .svg 삭제 작동을하지만 루게릭 병을 거라고 무엇을 o. 고아가 없도록 일치하는 .png 파일을 삭제하는 것. 나는 맹목적으로 Handling the Delete Event on Watch recipe을 신뢰하고 있으므로이 수정을 실험하기 위해 Gulp/JS 지식의 수준을 이미 벗어났습니다.

미리 감사드립니다. .png 파일을 가정

답변

0

가 축소 된 .svg 파일과 같은 폴더에 생성되고, 다음과 같은 작업을해야합니다 :

watchSvg.on('change', function(event) { 
    if (event.type === 'deleted') { 
    var filePathFromSrc = path.relative(path.resolve('src'), event.path); 
    var destFilePath = path.resolve('dist', filePathFromSrc); 
    del.sync(destFilePath); 
    var pngDestFilePath = destFilePath.replace(/.svg$/, '.png'); 
    del.sync(pngDestFilePath); 
    } 
}); 
관련 문제