Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

almond + coffee script #60

Closed
ichernev opened this issue Jul 1, 2013 · 2 comments
Closed

almond + coffee script #60

ichernev opened this issue Jul 1, 2013 · 2 comments

Comments

@ichernev
Copy link

ichernev commented Jul 1, 2013

In the readme it is said, that almond supports plugins (like text and cs), but then the recommended use case is to bundle everything into one file and inline plugin resources, and stub out actual plugins, which means there is actually no need for "plugin support", because when you say require(["cs!foo"]) it gets the code after define(["cs!foo"]...) and doesn't care about cs plugin.

So if I have all my modules written in coffee, and I've split them into two: first and second (modules in r.js build.js), where second is required dynamically on user interaction, how am I supposed to do it?

If I use something like require(['cs!second'], function(second) {..}), then it will search for cs plugin, which in turn will download coffee file, which is not optimal for production. I guess using a javascript bootstrap file for each module (in r.js) would solve that problem. But then I need full blown requirejs just for prepending baseUrl and fetching a script (because almond can't fetch).

@jrburke
Copy link
Member

jrburke commented Jul 2, 2013

almond cannot dynamically load code so trying to dynamically load the 'two' bundle will fail regardless if a loader plugin is used. If you want dynamic loading, bundle requirejs instead. An example, which shows how to map 'require' to 'requireLib' so it can be properly inlined in the build is in the second example here:

http://requirejs.org/docs/optimization.html#onejs

If second is already included with the built file with almond and no dynamic code loading is needed, just a dynamic require for it some time later, then what you can do for loader plugins that you just want a stub value for, you can use the stubModules config when using r.js to combine the files together:

https://github.com/jrburke/r.js/blob/master/build/example.build.js#L295

Closing as I believe stubModules is probably what will fix the problem.

@jrburke jrburke closed this as completed Jul 2, 2013
@ichernev
Copy link
Author

ichernev commented Jul 2, 2013

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants