Last active
October 10, 2015 22:52
-
-
Save tenodi/652f1383eeb6e27ccb9b to your computer and use it in GitHub Desktop.
Using html-minifier customAttrSurround for allowing swig template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is RegEx which is needed to be used if we want to catch something like: | |
<tr data-url="/beach" | |
{% if weather.isHot() %} | |
class="clickableRow" | |
{% endif %} | |
> | |
* Important notes: | |
* - We need \s* for catching all the whitespace before and after. | |
* - You can't make this for multiple attributes! In case you have multiple | |
* attributes, you need to make multiple if's too. | |
* - This is only RegEx for if-else. For blocks, swig values inside HTML | |
* elements, RegExs are not needed. | |
* - Multiple if's can be only separated by whitespace. | |
*/ | |
var open = /\s*\{%\s*if\s.+?%\}\s*/; | |
var close = /\s*\{%\s*endif\s*%\}\s*/; | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
htmlmin: { | |
dev: { | |
options: { | |
removeComments: true, | |
collapseWhitespace: true, | |
customAttrSurround: [[open, close]] | |
}, | |
files: [{ | |
// define your files here | |
}] | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-htmlmin'); | |
grunt.registerTask('default', ['htmlmin']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment