crisward / riot-routehandler

An angular-ui style minimalist route handler for riot.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Riot undefined in ES6 workflow?

john-goldsmith opened this issue · comments

commented

Does this package support an ES6 + Babel + Browserify workflow?

// app.js
import riot from 'riot';
import 'riot-routehandler';

Back in a browser, this produces Uncaught ReferenceError: riot is not defined. Am I missing a step?

You may need to add window.riot =riot
To make it global.

commented

I tried that, but since import statements are parsed first, and import 'riot-routehandler' throws an exception, it halts script execution. Also, making it a global sort of breaks the purpose of ES6 modules. Any ideas?

Riot route-handler isn't an es6 module. It also uses page.js which it requires in if it detects 'require' as a global function. I use it with browserify and common js modules. I've no problem making more es6 friendly or would accept a pull request as long as it doesn't break it.

What is the exception / error?

Sorry, you've already told me your error. Just to clarify

// app.js
import riot from 'riot';
window.riot = riot
import 'riot-routehandler';

Doesn't work?

commented

Correct -- import statements are hoisted, so when riot-routehandler gets imported and references riot, it doesn't know what that is.

I've recompiled the plugin as a umd module using riot's -m flag. It's in a branch https://github.com/crisward/riot-routehandler/tree/module, can you let me know if this works? It it does I'll look at a way of pushing this as part of the build, without breaking the current 'plain js' version. You probably just need to download the .js file from the lib folder.

As I've had no response on this for over a month, I'll close it. All riot tags don't include the riot runtime by default so I'm guessing this is more a build problem, rather than something specific to this module.