-
-
Notifications
You must be signed in to change notification settings - Fork 757
feat: support dynamic URL with new URL() context mode #12389
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
Conversation
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.
✅ Deploy Preview for rspack ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
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
NewUrlContextdependency type and correspondingURLContextDependencyclass for handling dynamic URL expressions - Extended
URLPluginparser to detect and create context dependencies whennew URL()is called with dynamic expressions andimport.meta.url - Enabled previously skipped test cases (
url/context-optionsandurl/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.
crates/rspack_plugin_javascript/src/dependency/context/url_context_dependency.rs
Outdated
Show resolved
Hide resolved
…text_dependency.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Rsdoctor Bundle Diff AnalysisFound 5 project(s) in monorepo. 📁 react-10kPath:
📦 Download Diff Report: react-10k Bundle Diff 📁 react-1kPath:
📦 Download Diff Report: react-1k Bundle Diff 📁 react-5kPath:
📦 Download Diff Report: react-5k Bundle Diff 📁 romePath:
📦 Download Diff Report: rome Bundle Diff 📁 ui-componentsPath:
📦 Download Diff Report: ui-components Bundle Diff Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 27.63KB from 47.69MB to 47.72MB (⬆️0.06%) |
CodSpeed Performance ReportMerging #12389 will not alter performanceComparing Summary
|
📝 Description
This PR adds support for dynamic URL imports using
new URL()with context mode, similar to webpack'smodule.parser.javascript.dynamicUrloption.🎯 Changes
NewUrlContextfor dynamic URL importsimport.meta.urlurl/context-optionsurl/pure-dep🎨 Behavior
When using
new URL(expression, import.meta.url)whereexpressionis a dynamic value:The plugin will:
🔗 Related Issues
This aligns rspack's behavior with webpack's
dynamicUrlfeature.✅ Testing
url/context-optionstest caseurl/pure-deptest case📚 Documentation