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
Optimize static site with Parcel v2 #8
Merged
Merged
Conversation
This file contains 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
What about Responsive Images? It might be possible to build a Parcel plugin based on https://nhoizey.github.io/images-responsiver/ ! |
@nhoizey That's clearly something I also want to address. I'll ping you once I go down this path |
|
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.
DISCLAIMER: Everything here is highly opinionated and dependent on my own context: building my site.
Eleventy claims to be a simple static site generator and it isπ By default it does not care much about your assets or how you want them to be processed.
Some users are asking for an official asset pipeline but I don't think Eleventy should step into this territory. Right now, it mostly focuses on contents and I think it's a good thing. It's why I came to try it in the first place.
I strongly believe in decoupling things. Each layer should do one thing and do it well. Each layer should know as little as possible about other layers. In the context of my own site, I want to decouple this two layers:
Build step
When I say "build", I mean what Eleventy can do right now:
Once this phase is done, I expect the output to be a valid static site with standard Web assets (HTML, CSS, JS, images, videos, fonts...) that I could host online as is. Nothing that cannot run in a browser.
DISCLAIMER: I don't want (and don't think I will need) to use things like TypeScript, Sass or any other transpiled languages like that for my site. Therefore, right now, achieving this standard Web output with Eleventy is easy. I'm not sure what I would do if I needed to use those.
Optimize step
The next step is to "optimize" this static site. This is what I want for my site:
Those would be a bonus:
Remember, the output from the previous step consists of standard Web assets. This means this "optimize" step doesn't need to know about Eleventy. In theory:
Now which tool can achieve such a task list?
Just like visitors will mostly discover/fetch the assets of my site via the HTML pages they're browsing, I need a toolchain that takes all my HTML files as inputs and discover the dependencies from there. I need a "Web centric" toolchain.
Webpack and Rollup
I've been using Webpack and Rollup for several years on multiple projects so I looked once more at the docs and the available plugins. However, even if they can work with assets like CSS/Sass/Less or images, those tools are JavaScript bundlers by nature. They need to start from JavaScript (or JSX/TS/TSX) files because they were designed for this purpose. From there, they create the dependency graph with the different ES
imports
, even for assets like CSS or images which is not standard for non JavaScript files. The way I see it but it's just my opinion about those:This does not have the "Web centric" feeling I'm looking for.
I think I could achieve what I want with those but I would need to bend them (a lot) and I don't want to do that.
DISCLAIMER: I don't know much about Webpack v5 which just came out.
Good old Gulp
I use Gulp a lot in my past. I know what it does and it does it pretty well. Most of the task I need to achieve are one-to-one so Gulp is an awesome fit for this. They main dealbreaker is the "Add hashes to all assets" task. I used (again) gulp-rev. It works well, the task is easy. The problem is replacing the asset names/URLs with the one with hashes in all assets. An operation that should trigger a change on the hash each time you modify the content to replace a URL. It's a graph problem and Gulp is too low level to handle that properly. I use gulp-rev-rewrite but it failed in some situations and I really feel like its replacing strategy is too naΓ―ve for the challenge.
Parcel v2
When I looked at the docs and the blog I noticed a few things:
Parcel markets itself as the "zero configuration web application bundler". It's nice but I'm more of a 100% configuration personπ so I tried to make Parcel do nothing and add the stuffs I needed step by step. I spent a lot of time understanding its plugin system and its internals. It's really close to what I need.
As you can see in this PR (step by step), I was able to achieve a good part of my tasks:
Some details about this:
I really really like this tool. Apart from some details or yet to come features, it's really what I was looking for! Thank you Parcel teamπ π
Limitations and questions