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

RequireJS Isolation for WebJars in Subprojects #39

Open
michaelahlers opened this issue Mar 19, 2014 · 4 comments
Open

RequireJS Isolation for WebJars in Subprojects #39

michaelahlers opened this issue Mar 19, 2014 · 4 comments

Comments

@michaelahlers
Copy link

I'm trying to use the RequireJS support in subprojects, and I've run into a couple snags.

To start, org.webjars.play.RequireJS assumes the reverse router will live in a controllers package. I was able to come up with a copy that parameterizes that package name. However, I ran into another problem afterwards.

To prove my solution, I had one subproject's build.sbt depend on version X of a library, and the other subproject depend on version Y. Both end up loading version Y (the highest lexigraphically) as org.webjars.WebJarAssetLocator makes no distinction by project. Worse, if I remove the dependency from either project, both still have access.

My guess is this isn't easily solvable with Play's classloading (i.e., I can't spot any straight-forward way to give WebJarAssetLocator a kind of scope for discovery). That said, if this team has any ideas that could make this possible, I'm all ears.

If it'll help, I'll be happy to assemble a sample project.

@jamesward
Copy link
Member

Hmm... This is gonna be tricky. In the meantime you can pretty easily manually do what org.webjars.play.RequireJS is doing. It is basically just:

<script>
@Html(org.webjars.RequireJS.getSetupJavaScript(routes.WebJarAssets.at("")))
</script>

<script data-main="/assets/index" src="@routes.WebJarAssets.at(WebJarAssets.locate("require.min.js"))"></script>

Let me know if that helps.

@michaelahlers
Copy link
Author

Thanks for the tip, @jamesward! I wasn't able to get that approach working, but I only took a quick stab and I've got to switch gears now (I'll circle back later). I'm guessing this issue might shake out if there ends up being a well-engineered solution to the latter. On that note, would you like a Gist of my project?

@jamesward
Copy link
Member

Sure! A simple reproducible project will definitely help us get this figured out.

@scaryroy
Copy link

Hi! I'm just a few months into play & scala, and I'm experiencing this problem.

i am quite interested in how you got it working @michaelahlers!

Currently, in a main.scala.html, it looks like:

@Html(org.webjars.play.RequireJS.setup("javascripts/app"))

And in a subproject.routes, it looks like:

GET     /webjars/*file              controllers.WebJarAssets.at(file)

both of which gives me an error. Some pointers would be nice =)

Thanks in advance!

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

3 participants