-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
support require.context #4399
support require.context #4399
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
10 Ignored Deployments
|
✅ This changes can build |
🟢 CI successful 🟢Thanks |
dd8a7f3
to
ebc54b7
Compare
ebc54b7
to
337bad1
Compare
337bad1
to
75b3783
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.
The approach is a bit inefficient from incremental compilation point of view, but we can move that to tech dept:
- adding/removing a file in the root directory with walk the whole directory again (list_dir is recomputed)
- This could be solved by using a tree reprensentation instead of
FlatDirList
- This could be solved by using a tree reprensentation instead of
- The module using
require.context
need to be re-analyzed once a file is added/removed from the context- This could be solved by moving the context map into a separate module
- And computing the require.context for static analysis only when a key is accessed from it. And making this a dedicated tt function
DirectoryEntry::File(path) => { | ||
if let Some(relative_path) = root.get_relative_path_to(&*path.await?) { | ||
if filter.is_match(&relative_path) { | ||
list.push((relative_path, *path)); |
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.
It need to apply some resolve options here. e. g. extensions
.
e.g. a file ./abc/index.ts
should have multiple keys: ./abc/index.ts
./abc/index
./abc/
or ./abc
a package.json with main
or exports
would also influence that. (webpack doesn't handle that case)
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.
How would the package.json
influence this?
The API seems to be file path based, so webpack's behavior kinda makes sense to me
_, | ||
box JsValue::WellKnownFunction(WellKnownFunctionKind::RequireContext), | ||
args, | ||
) => require_context_visitor(origin, args, in_try).await?, |
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.
static evaluation for require.context... You are really (over)killing it...
webpack doesn't even support that.
So I can do something fancy like:
const context = require.context("...");
const resolved = context.resolve("./a");
const imported = require(resolved); // <- usually this would be too dynamic
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.
yea, the static evaluation was the reason I didn't put the context into a separate asset/module
4bd7b9e
to
e86d3e0
Compare
e86d3e0
to
341008e
Compare
341008e
to
790faa9
Compare
Benchmark for 8966c65Click to view benchmark
|
790faa9
to
4621561
Compare
Benchmark for 3aada5bClick to view benchmark
|
Benchmark for 21e66c2Click to view benchmark
|
Benchmark for 4b488f6Click to view benchmark
|
9682829
to
ead9225
Compare
comments have been addressed
### What? add support for blur placeholder generation to turbopack add `StructuredImageModuleType` which is used with `ModuleType::Custom` to allow importing an image as `{ url, width, height, blurDataURL, blurWidth, blurHeight }` in contrast to next.js with webpack this will also generate blur placeholder in development instead of using a _next/image reference. This should lead to more production-like experience (at the cost of a little bit of compilation time). turbo PR: vercel/turborepo#4621 ### Why? Turbopack was crashing on `placeholder="blur"` before. fixes WEB-534 ### Turbopack changes * vercel/turborepo#4521 <!-- OJ Kwon - feat(contextcondition): support InPath contextcondition --> * vercel/turborepo#4601 <!-- Alex Kirszenberg - Chunking Context Refactor pt. 3: Address PR comments from pt. 2 --> * vercel/turborepo#4623 <!-- Tobias Koppers - exclude turborepo from turbopack bench tests --> * vercel/turborepo#4399 <!-- Leah - support require.context --> * vercel/turborepo#4610 <!-- OJ Kwon - test(subset): add mdx test into subset --> * vercel/turborepo#4624 <!-- Tobias Koppers - run benchmarks on windows and macOS too --> * vercel/turborepo#4620 <!-- Alex Kirszenberg - Make ContainmentTree fully generic --> * vercel/turborepo#4600 <!-- Tobias Koppers - add getChunkPath method --> * vercel/turborepo#4621 <!-- Tobias Koppers - add turbopack-image --> * vercel/turborepo#4639 <!-- Tobias Koppers - restrict snapshot path for windows path length limit --> * vercel/turborepo#4641 <!-- Tobias Koppers - put webp behind a feature flag -->
fix WEB-535
fix WEB-535