Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Shim Javascript Code #111

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

Closed
ajhager opened this issue Oct 23, 2014 · 6 comments
Closed

Shim Javascript Code #111

ajhager opened this issue Oct 23, 2014 · 6 comments

Comments

@ajhager
Copy link

ajhager commented Oct 23, 2014

I keep having the need to provide custom javascript with a GopherJS library. For something like AngularJS, it seems fair to ask a user to include the library manually, but with custom library code it becomes a chore.

I created a utility to get around this https://github.com/ajhager/shmi, but it adds a manual build step. I wonder if it would be helpful to provide a mechanism to bundle javascript automatically using GopherJS.

There are a few ways this could be handled, but I suggest perhaps:

import "github.com/gopherjs/gopherjs/js"

js.Provide("./myjscode.js")
// OR
js.Import("./myjscode.js")
// OR
js.Bundle("./myjscode.js")

The compiler could make sure any javascript files would only be bundled once, and raise an error if the files don't exist.

I am happy to work on this, but I would appreciate some feedback.

@neelance
Copy link
Member

I am not sure about this... I think a js.Import statement would not really fit to Go. Better might be to handle .js files just like .s files, which means to automatically include them when building a package with install. For build and run you would need to add the file as an argument.

@ajhager
Copy link
Author

ajhager commented Oct 25, 2014

That is a much better idea of course. I wasn't happy with my solution either, but I think the need is there.

@neelance
Copy link
Member

neelance commented Nov 2, 2014

Please give it a try and tell me if this works in your case. Thanks. :-)

@ajhager
Copy link
Author

ajhager commented Nov 2, 2014

My only issue is that my library isn't rebuilt if the .js files change, only if the .go files are. I haven't dug into the compiler enough to know if this would be possible to fix.

Otherwise, this is fantastic! Thanks for working on it.

@neelance
Copy link
Member

neelance commented Nov 2, 2014

Hey @ajhager , please be aware that I changed the extension to .inc.js because of 51e33b7#commitcomment-8401097. It is also checking the timestamp of those files now.

@ajhager
Copy link
Author

ajhager commented Nov 2, 2014

Thanks, it works great now. You even anticipated my next issue. Excellent!

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