Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

📝 Description

This PR adds support for dynamic URL imports using new URL() with context mode, similar to webpack's module.parser.javascript.dynamicUrl option.

🎯 Changes

  • Add new dependency type: NewUrlContext for dynamic URL imports
  • Implement URLContextDependency: New dependency class to handle context-based URL resolution
  • Implement URLContextDependencyTemplate: Template for generating code for URL context dependencies
  • Extend URLPlugin: Parser plugin now supports dynamic URL expressions with import.meta.url
  • Register dependencies: URLContextDependency factory and template registered in compilation
  • Enable tests: Previously skipped test cases now enabled:
    • url/context-options
    • url/pure-dep

🎨 Behavior

When using new URL(expression, import.meta.url) where expression is a dynamic value:

// Example: Dynamic import with pattern
const name = 'file1';
const url = new URL(`./assets/${name}.png`, import.meta.url);

The plugin will:

  • Create a context dependency to resolve all potential matches
  • Support magic comments for include/exclude patterns
  • Use sync context mode for URL resolution

🔗 Related Issues

This aligns rspack's behavior with webpack's dynamicUrl feature.

✅ Testing

  • Enabled and passing: url/context-options test case
  • Enabled and passing: url/pure-dep test case

📚 Documentation

  • Documentation updated (if applicable)
  • Tests added/updated
  • Changelog entry added (in commit message)

This PR adds support for dynamic URL imports using new URL() with context mode, similar to webpack's module.parser.javascript.dynamicUrl option.

## Changes

- Add new dependency type NewUrlContext for dynamic URL imports
- Implement URLContextDependency and URLContextDependencyTemplate to handle context-based URL resolution
- Extend URLPlugin parser plugin to support dynamic URL expressions with import.meta.url
- Register URLContextDependency factory and template in compilation
- Enable previously skipped test cases: url/context-options and url/pure-dep

## Behavior

When using new URL(expression, import.meta.url) where expression is a dynamic value:
- The plugin creates a context dependency to resolve all potential matches
- Supports magic comments for include/exclude patterns
- Uses sync context mode for URL resolution

This aligns rspack's behavior with webpack's dynamicUrl feature.
Copilot AI review requested due to automatic review settings December 8, 2025 12:00
@netlify
Copy link

netlify bot commented Dec 8, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 59fdb4c
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6937aa474e5b190008d7f4d8
😎 Deploy Preview https://deploy-preview-12389--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: feature release: feature related release(mr only) labels Dec 8, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements support for dynamic URL imports using new URL() with context mode, enabling rspack to handle dynamic URL expressions similar to webpack's module.parser.javascript.dynamicUrl feature. The implementation creates a context dependency that resolves all potential URL matches at build time when the URL path contains dynamic expressions.

Key Changes:

  • Added NewUrlContext dependency type and corresponding URLContextDependency class for handling dynamic URL expressions
  • Extended URLPlugin parser to detect and create context dependencies when new URL() is called with dynamic expressions and import.meta.url
  • Enabled previously skipped test cases (url/context-options and url/pure-dep)

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/rspack_core/src/dependency/dependency_type.rs Added NewUrlContext enum variant and its string representation
crates/rspack_plugin_javascript/src/dependency/context/url_context_dependency.rs New file implementing URLContextDependency and its template for code generation
crates/rspack_plugin_javascript/src/dependency/context/mod.rs Added module declaration and public exports for URL context dependency
crates/rspack_plugin_javascript/src/parser_plugin/url_plugin.rs Extended parser to handle dynamic URL expressions by creating context dependencies
crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs Registered dependency factory and template for URL context dependencies
crates/rspack_plugin_javascript/src/visitors/dependency/context_dependency_helper.rs Added Debug derive to ContextModuleScanResult struct
tests/rspack-test/configCases/url/pure-dep/test.filter.js Removed test filter to enable the test case
tests/rspack-test/configCases/url/pure-dep/rspack.config.js Updated comment to reflect that dynamicUrl is always enabled in rspack
tests/rspack-test/configCases/url/context-options/test.filter.js Removed test filter to enable the test case
tests/rspack-test/configCases/url/context-options/rspack.config.js Updated comment to reflect that dynamicUrl is always enabled in rspack

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…text_dependency.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

Rsdoctor Bundle Diff Analysis

Found 5 project(s) in monorepo.

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

📌 Baseline Commit: c1aabb8e00 | PR: #12370

Metric Current Baseline Change
📊 Total Size 5.7 MB 5.7 MB 0 B (0.0%)
📄 JavaScript 5.7 MB 5.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-10k Bundle Diff

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

📌 Baseline Commit: c1aabb8e00 | PR: #12370

Metric Current Baseline Change
📊 Total Size 823.6 KB 823.6 KB 0 B (0.0%)
📄 JavaScript 823.6 KB 823.6 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-1k Bundle Diff

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

📌 Baseline Commit: c1aabb8e00 | PR: #12370

Metric Current Baseline Change
📊 Total Size 2.7 MB 2.7 MB 0 B (0.0%)
📄 JavaScript 2.7 MB 2.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-5k Bundle Diff

📁 rome

Path: ../build-tools-performance/cases/rome/dist/rsdoctor-data.json

📌 Baseline Commit: c1aabb8e00 | PR: #12370

Metric Current Baseline Change
📊 Total Size 984.3 KB 984.3 KB 0 B (0.0%)
📄 JavaScript 984.3 KB 984.3 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: rome Bundle Diff

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

📌 Baseline Commit: c1aabb8e00 | PR: #12370

Metric Current Baseline Change
📊 Total Size 2.1 MB 2.1 MB 0 B (0.0%)
📄 JavaScript 2.0 MB 2.0 MB 0 B (0.0%)
🎨 CSS 83.0 KB 83.0 KB 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: ui-components Bundle Diff

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

📦 Binary Size-limit

Comparing 59fdb4c to feat: support [relative-resource-path] in moduleFilenameTemplate (#12370) by Cong-Cong Pan

❌ Size increased by 27.63KB from 47.69MB to 47.72MB (⬆️0.06%)

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 8, 2025

CodSpeed Performance Report

Merging #12389 will not alter performance

Comparing feat/url-context-dependency (59fdb4c) with main (c1aabb8)

Summary

✅ 17 untouched

@LingyuCoder LingyuCoder requested a review from SyMind December 9, 2025 05:13
@LingyuCoder LingyuCoder merged commit b0beb31 into main Dec 9, 2025
99 of 104 checks passed
@LingyuCoder LingyuCoder deleted the feat/url-context-dependency branch December 9, 2025 05:28
@CPunisher CPunisher mentioned this pull request Dec 17, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants