generated from dustin-jw/eleventy-starter-lite
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1f26677
chore: install esbuild
dustin-jw cebbaaa
chore: incorporate esbuild into build process
dustin-jw 32cda9e
refactor: reference built JS files
dustin-jw b525a65
refactor: move/rename game selection functions
dustin-jw 3f700d9
refactor: move pagination functions to helpers
dustin-jw 9613ac4
fix: update page title to match randomized order
dustin-jw 6056e28
refactor: pull most logic into helper functions/files
dustin-jw 9e17e36
style: add clarifying comments
dustin-jw dcd2cac
style: remove empty line before JSON output
dustin-jw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as esbuild from 'esbuild'; | ||
import { config } from 'dotenv'; | ||
|
||
config(); | ||
|
||
const isProduction = process.env.NODE_ENV !== 'development'; | ||
|
||
const options = { | ||
entryPoints: ['src/js/*.js'], | ||
format: 'esm', | ||
bundle: true, | ||
splitting: true, | ||
outdir: 'dist/js', | ||
// run `npx browserslist` to find updated minimum versions to set here | ||
target: ['chrome109', 'edge109', 'firefox109', 'safari15.5', 'opera94'], | ||
sourcemap: isProduction ? false : 'inline', | ||
minify: isProduction, | ||
logLevel: 'info', | ||
}; | ||
|
||
if (!isProduction) { | ||
// watch for changes and rebuild during development | ||
let context = await esbuild.context(options); | ||
await context.watch(); | ||
} else { | ||
// build once and exit | ||
await esbuild.build(options); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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 runningesbuild
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.