UNPKG

grunt-filerev-match-replace

Version:
31 lines (28 loc) 855 B
var script_search = /<script[^>]+>/gi; var script_src_capture = /src\s*=\s*("([^"]+)"|'([^']+)')/i; module.exports = { accept: function(filetype) { return filetype === 'html'; }, analyze: function(content) { var replace_map = {}, matches = content.match(script_search); if (!matches) { return null; } matches.forEach(function(item) { if (replace_map[item]) { replace_map[item].count ++; return; } var caputre_matches = item.match(script_src_capture); if (caputre_matches && caputre_matches[2]) { replace_map[item] = { origin_url: caputre_matches[2], count: 1 }; } }); return replace_map; } };