From 263c50d28aa07f601f23c9d52c537d8817c5e227 Mon Sep 17 00:00:00 2001 From: baranar1 Date: Wed, 21 Dec 2016 12:20:36 +0300 Subject: [PATCH] Handle exceptions from uglify and cleancss modules --- tasks/inline.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tasks/inline.js b/tasks/inline.js index 556077d..96cc5a1 100644 --- a/tasks/inline.js +++ b/tasks/inline.js @@ -130,7 +130,13 @@ module.exports = function(grunt) { if(!isRemotePath(src) && src.indexOf(options.tag)!=-1){ var inlineFilePath = path.resolve( path.dirname(filepath), src ).replace(/\?.*$/, ''); // 将参数去掉 - var c = options.uglify ? UglifyJS.minify(inlineFilePath).code : grunt.file.read( inlineFilePath ); + + try { + var c = options.uglify ? UglifyJS.minify(inlineFilePath).code : grunt.file.read( inlineFilePath ); + } catch (err) { + grunt.fail.warn(err); + } + if( grunt.file.exists(inlineFilePath) ){ ret = ''; }else{ @@ -206,7 +212,12 @@ module.exports = function(grunt) { return matchedWord.replace(imgUrl, newUrl); }); - fileContent = options.cssmin ? CleanCSS.process(fileContent) : fileContent; + + try { + fileContent = options.cssmin ? CleanCSS.process(fileContent) : fileContent; + } catch(err) { + grunt.fail.warn(err); + } return fileContent; }