-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: support JS build process #141
Conversation
✅ Deploy Preview for triviaccessibility ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
1525f37
to
5272682
Compare
5272682
to
08dc1d9
Compare
08dc1d9
to
da4d2eb
Compare
3a826a3
to
25e1425
Compare
25e1425
to
6056e28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again, I don't have a great grasp on the repo quite yet, but it seems to function as expected, according to the validation instructions. I only wanted to bring up one thing, with the minified dist/js/multiple-choice.js
file. I haven't looked at many minified files, so are those last 3 lines ok? I wasn't sure if literally EVERYTHING should be smooshed together without indentation.
If that looks like you'd expect it, I'll approve!
Questions (purely for my own understanding):
- It seems like some of this work was refactoring- pulling functions from larger files, into smaller pieces. How do you determine what gets extracted to a separate file, vs. just stays within a larger file?
- What exactly is the
.ejs
file for? After a quick google, it seems it means Embedded (or maybe effective?) JavaScript. It looks like it's transforming JSON? - I've done zero research on this, but I've seen the
robots.txt
a couple places lately. Can you share any like, resources or articles or anything, so I can understand what that file is doing? - What do "Distractor 1" and "Distractor 2" mean? Why those words? (again, if that's something I should just google, let me know)
It wouldn't be me without extra questions, right?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the pages in all
...those correspond to when a user clicks on the "All Questions" in a game type, correct? I was a little confused at first, since those files are almost identical, but that's what I could gather.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there's a lot of repetition that we could probably refactor to make it a little easier to manage, but there are enough small differences that would make that a hassle. Honestly, it might be easier to tag each question in Airtable as "All", then delete the all
folder entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure what this file is doing. It's setting a bunch of variables/data based on whether or not the environment is dev/local or production I think, but I don't really know why. Some of them I get- like minify is true for the production files (so after the site is built). Same for bundle, and I understand outdir
...
Maybe I need to look up esbuild.context()
? Would that be a good place to start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esbuild is similar to webpack, which you might have seen before, but effectively it's a build tool for bundling/smooshing together JS (it can do other things, but that's the basic idea).
What could probably be clearer is that if isProduction
is false, then we're running esbuild
in "watch" mode, so it will rebuild whenever you save a file that affects the entry points. Otherwise, we just build our output JS files once and call it a day. I'll add some comments to clarify that behavior because I don't think it's intuitive.
@dustin-jw Oh, actually there was one more thing! I don't know if it's related to work on this PR, or if it should be an extra card/issue. But I do get a flash of the questions index number (I think) before it changes to its randomized question number (if that makes sense). Screen.Recording.2024-02-23.at.3.11.25.PM.movI don't really make it clear in the video, but it happens when I click either the "Next" and "Previous" buttons. |
The minified file looks correct to me. The reason those last few lines stand out is due to a multi-line string, which is preserving the original whitespace. It's not strictly necessary in this case, but that is generally what we want to happen with those kinds of strings 👍
Some people take it to an extreme, like "one file for every function", while others will just put everything in one file. It's been a while since I wrote this PR, but I think my rule of thumb was to group related behaviors and keep entry points slim, so for example
Eleventy supports a ton of different templating languages, and EJS is one of them. I forget why I chose EJS for this instead of Nunjucks like everything else, but I'm guessing it had something to do with better support for JSON formatting.
The short answer is it isn't doing anything. The long answer is that it's a file that web crawlers look for and pinky promise to respect while indexing your site or scraping it to feed ChatGPT. There are things that you can put into a
Those are just the words we picked for the wrong multiple choice answers. You can see them in the column names in Airtable, so each multiple choice question has a right answer and up to two answers that distract you from the correct one.
I love the questions! It makes me think about things that I would totally gloss over otherwise or assume makes sense to everyone. |
This is a tricky thing to address because of how the site is built. During deployment, Eleventy grabs all the data it needs and builds every HTML file that we need for the site, and the HTML matches the permalinks, so |
Description
This work replaces our rudimentary mechanism for including JS on pages with a more robust build process using esbuild. This will make it easier to contribute JS and will give us some performance boosts from minification, code splitting, and caching. Notable changes include:
dist/js
instead of inlined in HTML filesTo Validate
npm start
npm run build
and inspect thedist/js
folder. All files should be minified and re-used code should be inchunk-<id>.js
file(s) that get imported in other files