-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
add basic webpack loader support #3284
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
9 Ignored Deployments
|
Benchmark for fd8b959Click to view benchmark
|
🟢 CI successful 🟢Thanks |
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.
A few nits and questions, but otherwise :ship-it:
crates/next-core/src/next_config.rs
Outdated
let Some(experimental) = this.experimental.as_ref() else { | ||
return Ok(WebpackLoadersOptionsVc::cell(WebpackLoadersOptions::default())); | ||
}; | ||
let Some(turbopack_webpack_loaders) = experimental.turbopack_webpack_loaders.as_ref() else { | ||
return Ok(WebpackLoadersOptionsVc::cell(WebpackLoadersOptions::default())); | ||
}; |
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.
let Some(experimental) = this.experimental.as_ref() else { | |
return Ok(WebpackLoadersOptionsVc::cell(WebpackLoadersOptions::default())); | |
}; | |
let Some(turbopack_webpack_loaders) = experimental.turbopack_webpack_loaders.as_ref() else { | |
return Ok(WebpackLoadersOptionsVc::cell(WebpackLoadersOptions::default())); | |
}; | |
let Some(turbopack_webpack_loaders) = this.experimental.as_ref().and_then(|experimental| experimental.turbopack_webpack_loaders.as_ref()) else { | |
return Ok(WebpackLoadersOptionsVc::cell(WebpackLoadersOptions::default())); | |
}; |
@@ -22,6 +44,7 @@ pub struct ModuleOptionsContext { | |||
pub enable_styled_components: bool, | |||
pub enable_styled_jsx: bool, | |||
pub enable_postcss_transform: Option<PostCssTransformOptions>, | |||
pub enable_webpack_loaders: Option<WebpackLoadersOptions>, |
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 seems weird that this is worded as a boolean (enable_something
) instead of just webpack_loaders
, like we have for other options. Same comment goes for PostCSS.
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. pub enable_styled_jsx: bool,
could also be pub styled_jsx: bool,
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.
Let's do that in a follow-up PR
#[turbo_tasks::function] | ||
fn read(&self, _fs_path: FileSystemPathVc) -> Result<FileContentVc> { | ||
bail!("Reading is not possible from the virtual filesystem for the dev server") | ||
bail!("Reading is not possible from the marker filesystem for the server") |
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.
What is a "marker" file system?
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.
We only used it for paths and do not read/write from it. A virtual filesystem would allow to read/write...
"check": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"loader-runner": "^4.3.0" |
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 do we ensure this is installed by the user? Is it one of Next.js' transitive dependencies? Or should we compile it and distribute it with turbopack?
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.
Sadly it's not accessible from next/dist. We probably should exposed that as compiled packages. It's currently bundled into webpack
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.
Currently the user need to install it to use this feature. That's fine for the first iteration...
|
||
// environment | ||
"jsx": "react-jsx", | ||
"lib": ["ESNext", "DOM"], |
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.
Does it make sense to include DOM type definitions for this package?
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.
No. I just copied the tsconfig from next-dev^^
} | ||
|
||
#[turbo_tasks::value] | ||
struct WebpackLoadersedAsset { |
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.
struct WebpackLoadersedAsset { | |
struct WebpackLoadersProcessedAsset { |
It looks like it would be easier to implement this with napi-rs, @sokra do you mind if I make a prototype based on this with napi-rs? |
A few questions?
|
bed6138
to
824f34b
Compare
Why do we need to distribute turbopack as a binary? IMO the entry file can be a JavaScript file that calls the napi-rs wrapped Rust function like next-swc.
We can use
Yes, sure; we can keep all the ability in turbopack with napi-rs, including the memory fs, resolve alias, and even dev-server. |
Benchmark for e448d45Click to view benchmark
|
.map(|(file, (content, _source_map))| { | ||
// TODO handle SourceMap | ||
VirtualAssetVc::new( | ||
ServerFileSystemVc::new().root().join(&file), |
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.
Should we be passing in the file system to use?
fn webpack_loaders_executor(project_root: FileSystemPathVc, context: AssetContextVc) -> AssetVc { | ||
EcmascriptModuleAssetVc::new( | ||
VirtualAssetVc::new( | ||
project_root.join("__turbopack__/webpack-loaders-executor.ts"), |
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.
Shouldn't that be [embedded_modules]/@vercel/turbopack-node
add the minimum to run a simple raw-loader (see test case) * add `experimental.turbopackWebpackLoaders` to next.config.js * key is extension like `".mdx"`, value is an array of loaders like `["mdx-loader"]`
add the minimum to run a simple raw-loader (see test case) * add `experimental.turbopackWebpackLoaders` to next.config.js * key is extension like `".mdx"`, value is an array of loaders like `["mdx-loader"]`
add the minimum to run a simple raw-loader (see test case) * add `experimental.turbopackWebpackLoaders` to next.config.js * key is extension like `".mdx"`, value is an array of loaders like `["mdx-loader"]`
add the minimum to run a simple raw-loader (see test case) * add `experimental.turbopackWebpackLoaders` to next.config.js * key is extension like `".mdx"`, value is an array of loaders like `["mdx-loader"]`
add the minimum to run a simple raw-loader (see test case) * add `experimental.turbopackWebpackLoaders` to next.config.js * key is extension like `".mdx"`, value is an array of loaders like `["mdx-loader"]`
add the minimum to run a simple raw-loader (see test case)
experimental.turbopackWebpackLoaders
to next.config.js".mdx"
, value is an array of loaders like["mdx-loader"]