-
-
Save brikis98/1794839 to your computer and use it in GitHub Desktop.
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
var getName = require('name').getName; | |
exports.hello = function() { | |
return "Hello " + getName(); | |
}; |
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
<script type="text/javascript" src="/js/inject.js"></script> | |
<script type="text/javascript"> | |
require.setModuleRoot("http://example.com/js/modules"); | |
require.run("program"); | |
</script> |
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
<script type="text/javascript" src="/js/modules/name.js"></script> | |
<script type="text/javascript" src="/js/modules/hello.js"></script> | |
<script type="text/javascript" src="/js/modules/program.js"></script> |
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
exports.getName = function() { | |
return prompt("What's your name?"); | |
}; |
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
var hello = require('hello').hello; | |
alert(hello()); |
Ok, now it works. I had to rename a folder.
However, I can't get this lib to work offline (without a server).
I'm using Firefox+Firebug, I get no error, just this line
Porthole: Using built-in browser support
Then nothing. No error, no alert.
@Serpenthelm: I believe Inject uses XHR to fetch JS files, so you need a valid domain. This means running locally, without a server, won't work, since a file:///
path is probably not going to be recognized as a valid domain. @jakobo could comment more, but I think you'll need to fire up some sort of server (e.g. apache) to test so you can use localhost
as a domain.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Serpenthelm: open up the console in your browser and see if there are any JS errors. My guess is that your module root isn't being set correctly. For example, if you are testing this code by opening up
http://localhost:3000/index.html
in your browser, you'll need to update the code torequire.setModuleRoot("http://localhost:3000/js/modules");
.