Skip to content

Commit 51622cf

Browse files
feat: support custom image loaders in turbopack
1 parent a211566 commit 51622cf

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/next-swc/crates/next-core/src/next_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ pub struct ImageConfig {
310310
pub image_sizes: Vec<u16>,
311311
pub path: String,
312312
pub loader: ImageLoader,
313+
pub loader_file: Option<String>,
313314
pub domains: Vec<String>,
314315
pub disable_static_images: bool,
315316
#[serde(rename(deserialize = "minimumCacheTTL"))]
@@ -330,6 +331,7 @@ impl Default for ImageConfig {
330331
image_sizes: vec![16, 32, 48, 64, 96, 128, 256, 384],
331332
path: "/_next/image".to_string(),
332333
loader: ImageLoader::Default,
334+
loader_file: None,
333335
domains: vec![],
334336
disable_static_images: false,
335337
minimum_cache_ttl: 60,

packages/next-swc/crates/next-core/src/next_import_map.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,21 @@ async fn insert_next_server_special_aliases(
521521
external_if_node(project_path, "next/dist/compiled/@opentelemetry/api"),
522522
);
523523

524+
let image_config = next_config.image_config().await?;
525+
if let Some(loader_file) = image_config.loader_file.as_deref() {
526+
import_map.insert_exact_alias(
527+
"next/dist/shared/lib/image-loader",
528+
request_to_import_mapping(project_path, loader_file),
529+
);
530+
531+
if runtime == NextRuntime::Edge {
532+
import_map.insert_exact_alias(
533+
"next/dist/esm/shared/lib/image-loader",
534+
request_to_import_mapping(project_path, loader_file),
535+
);
536+
}
537+
}
538+
524539
match ty {
525540
ServerContextType::Pages { pages_dir } | ServerContextType::PagesApi { pages_dir } => {
526541
insert_alias_to_alternatives(

0 commit comments

Comments
 (0)