Skip to content

Instantly share code, notes, and snippets.

@acstll
Last active December 21, 2015 23:09
Show Gist options
  • Save acstll/6380095 to your computer and use it in GitHub Desktop.
Save acstll/6380095 to your computer and use it in GitHub Desktop.
Browserify transform module for requiring html files through domify.
var through = require('through');
module.exports = function (file) {
if (!/\.html/.test(file)) return through();
var buffer = '';
return through(write, end);
function write (chunk) {
buffer += chunk.toString();
}
function end () {
this.queue(wrap());
this.queue(null);
}
function wrap () {
var string = buffer
.replace(/\n|\t/g, '')
.replace(/'/g, ''')
.trim();
return [
"var domify = require('domify');\n\n",
"module.exports = domify('" + string + "');",
].join('');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment