-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
is it possible to use this in the browser? If so how? #2
Comments
Yes. You can either pre-compile the files, which is simple to do and understand. Invoke the compiler from the command line, e.g:
Much easier (for the developer!) is to have node load and compile them on demand. You can do this by using the following snippet (with Express, but it works with almost anything that understands Node request handlers):
This should be read as: "Make available on the URL /js any files that exist in (dirname)/www/nodent which end in ".js", and transpile them on the fly using the "es7" semantics. The (undocumented - sorry) options for generateRequestHandler() are: generateRequestHandler(pathToLocalFiles,fileNameRegexp,options) ;
Additionally, you need the following snippet somewhere in your browser code (apologies again - not well documented).
I don't think I've missed anything out - if it doesn't work let me know. There's an example of a server that does this at https://github.com/MatAtBread/ApiPublisher/blob/master/test/server.js (another project of mine that use nodent). If you want to push a doc or Wiki page with a decent How-To, feel free :) |
I think nodent would get better traction if it supported browserify and was documented as such. Eg. our application uses gulp and browserify and we tried using async suport using babel, but the source maps where not really usable. nodent looks really nice for that. |
I'm not familiar with browserify (tho a quick look at the site gives me the idea). Can you point me at the appropriate docs for deploying "browserify" plugins or whatever, and I'll take a look. Alternatively, do you know what in nodent stops in working? |
@matthiasg I love a challenge, so a built a browserify-nodent. Take a look and let me know if it works for you. https://www.npmjs.com/package/browserify-nodent |
@MatAtBread .. wow .. now THAT was fast :) .... i will try it today.. ! I hope i get the sourcemaps to work with babel after your compiler ... that would be awesome. I looked into nodent a few months ago and decided we can use async now, but we started on the browser side (for our v2) and thus i used babel async first. but after some hours with it yesterday, i found the source maps to be lacking a little. The only concern i still have with nodent in the browser is the context your code runs in (thats what i will test today). The context is important in our Angular 1.x app since if you don't use the window.Promise class then it will not be bound to angular and thus angular won't refresh itself. I could simply patch your code most likely but i will test first. |
The browserify will default to "es7" mode. You'll need to add a "use nodent-promise" directive to use Promises, and as you'll see, it it will use whatever resolves to Promise. Source maps with well, but I didn't try with Babel in the chain. FYI, try the links in https://github.com/MatAtBread/nodent/blob/master/README.md#performance. In es7 (which should with fine with Promises), nodent is about 10x faster than Babel's implementation using regenerator! Let me know if you have a problem with the transformer.... I'm new to browserify! |
Will transpiling work in the browser? I am considering to use it to transpile asynchronous validation functions generated by ajv. It doesn't do it yet, but I thought if it did and it used async/await then would I be able to transpile them? Check issue ajv-validator/ajv#40 for the context. |
If you mean run the whole transpiler in the browser, the short answer is no. That having been said, I've not tried in with browserify (there is a browserify plugin, but it's many for use on the command line). If you mean transpiration in advance or on-the-fly, then yes, this use case is supported and in use in production. |
...and to be accurate, there's no code in the core transformer that couldn't run in a browser, so use via browserify in situ should be possible. |
I tried browserifying nodent, it does it ok... Why do you think it won't work in the browser? I guess I'll try :) |
I don't - "use via browserify in situ should be possible" - I've just not tried |
No description provided.
The text was updated successfully, but these errors were encountered: