TimBeyer / html-to-vdom

Converts an HTML string into a virtual DOM
172 stars 41 forks source link

question: is it possible to use it without node? #28

Closed paulocheque closed 8 years ago

paulocheque commented 8 years ago

I would like to avoid the require function and use the basic window.something syntax, because the legacy of my current project. Is that possible?

TimBeyer commented 8 years ago

You could use browserify with the standalone option to make a bundle that you can load with a script tag in your website. Since you also need the virtual-dom dependency, you'll have to create a new project folder and thennpm install html-to-vdom virtual-dom. Then you create an index.js that looks like this

var VNode = require('virtual-dom/vnode/vnode');
var VText = require('virtual-dom/vnode/vtext');

var convertHTML = require('html-to-vdom')({
    VNode: VNode,
    VText: VText
});

module.exports = convertHTML;

That's the module we want to export to the browser, since it contains everything it needs to run standalone. After that run browserify ./index.js -s convertHTML > html-to-vdom.js. The html-to-vdom.js contains everything that's necessary then to run standalone. Add it to your page and you should have window.convertHTML available.

paulocheque commented 8 years ago

Thanks! I did that and it worked.

The virtual-dom offers a standalone version in its dist/ dir. Maybe you guys could include something like that too in the future!

Best,