-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Should we use a bundler for our web assets #610
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
Comments
I would personally avoid introducing Webpack & co, but don't really see the need to be as aggressive as you suggest in reducing JavaScript usage either. Let's take the current pain-points:
What about ditching Stylus altogether? CSS custom properties support everything in RFC 1985 except UC Browser for Android.
We recently split it into modules - we could just put each module into it's own file, though it would mean more files to copy from Rust.
I would not worry to much about it since it's 19KB.
No sure how FontAwesome works, but can't we just manually extract them and place them in the codebase? |
@sorin-davidoi I don't disagree with your points, the 'current situation' is not that bad, and it was wrong to present this as a dichotomy of choice. My primary reason for considering this was to fix The Debian Problem. I'll reformat the issue because I'm thinking about this in a slightly different way now. |
I'm also keen to fix The Debian Problem, although from my limited experience with webpack I worry we may just be replacing one problem with another. That said, we probably need a better system than copying minified JavaScript and CSS around. Abusing feature flags to One possible solution is to pull all the CSS/JS stuff out of the
I think this could also go down as an advantage. Quite a lot of people have complained about the generated books not being fully available offline because we use CDNs and such (see #511 and the linked issues). If all necessary assets are bundled into the |
Not sure whether adding a build-time dependency to a gigantic JavaScript codebase (which most bundlers are) will make Debian happy, as I don't think these are already packaged by debian. But @infinity0 knows more. I think the best solution to this would be to be more humble with JavaScript usage. I think right now it is pretty rude how much JavaScript mdbook needs and how much it is requesting. Why does it have to send an XHR request to crates.io??? |
A good idea in general, but there is no way to implement the current feature-set while also removing JavaScript dependencies.
In order to enable Rust snippets to be executed. I agree that this is not needed for pages without Rust code, so this can be optimized (we can also delay the request until the "Run" button is clicked). |
Another option is to use Sass instead of stylus. There is sass-rs, a Rust wrapper around libsass. In addition to ditching stylus, it would allow us to easily let users define new themes by creating a new file defining a couple of variables and compile it at runtime into the CSS file. Maybe that is also possible with CSS and custom properties? I don't know, I haven't used them yet. |
Yes, and they can also be tweaked at runtime (example). |
I agree re: CDNs. I'd be happy just removing them altogether. People have valid concerns, and I'm not sure it's worth keeping an option around just in case your browser has the exact version from the exact CDN cached just to save 100KB of bandwidth. I chose webpack over newer/simpler alternatives because it is already packaged in Debian , although it's in Sid, so it can't be in stable until... 2021? So there's a wrinkle I hadn't quite considered. We'd have to use something like YUI-Compressor, in the mean time. The fact that webpack wouldn't help Debian right now diminishes its usefulness in my eyes. I still think it would be useful to have some system to manage assets, even if its just a script or a rust tool. Since we're pinging @infinity0 I might as well ask for his opinion specifically. This is how I propose that an mdBook build would work for Debian:
Which leaves the following dependencies:
The JS dependencies would be vendored. We would then provide a way to either use them as-is, or to minify them using an existing stable Debian package. If FontAwesome is an issue we can provide a solution for that as well, like just ship the 4 PNGs that we use. |
Typically a bundler is only needed if the original code is a CommonJS/NodeJS module that don't have support for being used via If you don't want to serve CDN files, then just have the build script download them and copy them into a local relative path that is available in the webroot so For example, my current patches for mdBook can be seen here. Packing everything together would make these patches much much more awkward. |
Okay, I'm pretty convinced that webpack-et-al is not the solution for this problem. Rather than try to steer this thread towards some other ideas, I'm going to close this issue. Thank you all for your thoughts. |
There is also https://github.com/connorskees/grass that can compile scss and is a regular rust crate. With this we could improve the css situation specifically themes could be simplified by for example a css framework like bulma. I'm working currently on a feature where I want to avoid implement an overlay by hand and myself and rather rely on some foundation that is battle tested. Specifically here scss and a proper framework would save a lot of code and improve the maintainability with avoiding to pull in webpack and other npm packages. Any thoughts? |
My primary motivation for considering a bundler is to get full-featured Rust docs onto Debian: #495. The best way to do that would be to vendor our dependencies' source, and provide a way to produce minified builds for inclusion into mdBook. This could be a one-off system that most people ignore besides package maintainers. However, if we're doing the work to enable this, we may want to take advantage of some other benefits it may give.
Advantages:
Disadvantages:
The discussion has focused around alternatives to solving these problems without using a JS bundler. I'll try to summarize that idea here:
mdbook serve --theme <dir>
to edit theme without any build stepyui-compressor
, since it would likely only be used by Debian.The text was updated successfully, but these errors were encountered: