Example of using webpack and js modules alongside vanilla js :)#33
Draft
sneakers-the-rat wants to merge 2 commits intoneuroanatomy:masterfrom
Draft
Example of using webpack and js modules alongside vanilla js :)#33sneakers-the-rat wants to merge 2 commits intoneuroanatomy:masterfrom
sneakers-the-rat wants to merge 2 commits intoneuroanatomy:masterfrom
Conversation
Author
|
Also to be clear i don't guarantee this works 100% out of the box (hence not a PR for merging!) - for example the 3d viewer is having trouble loading the data from the main window, but certainly my doing and nothing wrong with the current implementation |
Member
|
Thanks a lot for this draft PR @sneakers-the-rat . We are learning so much with you! 🥰 We will look into it. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of: openjournals/joss-reviews#6336
Related to: #23
first of all i wanna be super clear this is not a PR that i am intending that you merge! I am making it as a PR just so it's easy to see the diff. feel free to close this any time!
OK previously i had said i would make an example of how you might package this up for distribution while also respecting your very lovely minimal, rock solid, no-hype, standards-based development style (which i love, did i say that already? i love it.)
this is not idiomatic ES6 or webpack, but it is my attempt at a transitional blend - some parts you might like, some parts you might hate, whatever works for you! I tried to touch as little of the code structure as i could.
The tricky thing about vanilla JS that imports everything into one global
windowscope is that it can be hard to reuse things, and so this is one step towards that - the<script>tags are removed from the html, and instead there are twoindex.jsentrypoints that import from files in the repository, as well as modules that are installed from npm.Y'all are very capable and i won't bore you with a tutorial, but here are some highlights:
configdirectory - you have one common config that is true for every build of the site, and then adevandprodconfig for, well, local development and production deployment!entrypoint creates a different js bundle. These take all the code that's imported there, minifies them, packs them into scopes, and then embeds that into the page. It used to be the case that CDNs were good because they let browsers cache the same file if it was used on multiple sites, but that's not really the case anymore. instead these bundles have a content hash, so whenever you change the code the browser knows to reload it, but can otherwise handle caching for just your site quite well. There are lots more fun optimization yak shaves you can get into, for example tree shaking where you can only bundle exactly the code you use from a package you import, and so on.devtool) that are well supported by modern browsers. Someone who just goes to use the site will get the minified js, but if someone wants to see the source, their browser will know to load the source maps and it will appear as normal js.index.jsfile has some examples usingexports-loaderfor adapting existing code that relies on global scope/side effects.three.js, and now if you want to update the version, etc. you just do that via npm and your lockfile.Gulpfile.jsthat's responsible for downloading local copies of the existing code from the CDN. Since that's your code, you could also package that up and distribute it via npm ( i see you have already done so with MRIViewer! ) or not, your choice. just another example of how to adapt styles.The new scripts in
package.jsonare the entrypoints to thedevandprodmode. Normally you would just callwebpackthere, but I am using a gulp -> webpack adapter that first makes sure the CDN scripts are downloaded and then runs webpack.at the end of al that you get a nice and tidy
distdirectory when you runnpm run build!My goal here was ultimately to show appreciation for your years of work and many wonderful web tools, and offer some example of how you might make those pieces play nicely together. I didn't get all the way to packing this as its own module, but in the future, if you decide this is something you like, you will be able to structure it so that you can, for example
exportsome functions from thresholdmann andimportthem in another site while keeping both separable and single-purpose.Anyway sorry this took so long, i'm going to finish up my review tomorrow! this was the last thing i wanted to do on that