Bankai Build with yo-yo/bel
See original GitHub issueI may be missing something fundamental here, so please bear with me.
Is it possible to use the bankai build
command to compile a file that uses something lower level than choo, like yo-yo/bel or even just the browser’s DOM API. Even without checking for window
, choo apps compile fine for me with bankai build
, but nothing else seems to work as I’d expect it to.
For example, the following example renders properly when using bankai start
and compiles without errors using bankai build
, but does not render when served over a static server.
var html = require('yo-yo');
var $header = function() {
return html` <header>
<nav class="navbar">
<a href="/" onclick=${linkHandler}>Home</a>
<a href="/about" onclick=${linkHandler}>About</a>
</nav>
</header>`;
function linkHandler(e) {
e.preventDefault();
console.log('link clicked', e.target.href);
router.emit(e.target.href);
}
};
if (typeof window !== 'undefined' && !module.parent) {
window.addEventListener('load', function() {
document.body.appendChild($header());
});
}
Similarly, using the DOM API doesn’t seem to work either.
if(type window !== 'undefiend' && !module.parent){
var el = document.creatElement('h1');
el.textContent = 'Hello World';
document.body.appendChild(el);
}
Am I missing a transform or something? I know there has to be something I’m just not understanding properly about the way Bankai is supposed to work. Any information to help point me in the right direction would be greatly appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
This did the trick! Thanks.
How common/uncommon are cyclical dependencies? It was quick hack on my part just to separate functionality into separate files to make things easier on me, but is it something that’s generally advised against?
Imo avoiding cyclical dependencies makes it easier to think about the order in which modules are executed; with cyclical
require()
calls you can get access to a module that has only executed half of its code, which can be confusing. Sometimes they are necessary tho so it’s not a strict rule.