Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tasks/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,18 @@ module.exports = function(grunt) {
var inlineFilePath = path.resolve( path.dirname(filepath), src ).replace(/\?.*$/, ''); // 将参数去掉

if( grunt.file.exists(inlineFilePath) ){
ret = matchedWord.replace(src, (new datauri(inlineFilePath)).content);

if (getFileSize(inlineFilePath) <= options.maxSize){
ret = matchedWord.replace(src, (new datauri(inlineFilePath)).content);
grunt.log.writeln('Inlining Image: '+ inlineFilePath.cyan + ' -> file size:' + getFileSize(inlineFilePath));
}else{
grunt.log.error("Omiting inlining of "+ inlineFilePath.red +" -> Image larger than "+ options.maxSize +".");
}

}else{
grunt.log.error("Couldn't find " + inlineFilePath + '!');
}

}
grunt.log.debug('ret = : ' + ret +'\n');

Expand Down Expand Up @@ -244,4 +252,17 @@ module.exports = function(grunt) {

return fileContent;
}

function getFileSize(fullPath) {

if (!fs.existsSync(fullPath)) {
return false;
}

var stats = fs.statSync(fullPath);
if (!stats.isFile()) {
return false;
}
return stats.size;
}
};