Struct rspack_resolver::ResolveOptions
source · pub struct ResolveOptions {Show 22 fields
pub tsconfig: Option<TsconfigOptions>,
pub alias: Alias,
pub alias_fields: Vec<Vec<String>>,
pub condition_names: Vec<String>,
pub description_files: Vec<String>,
pub enforce_extension: EnforceExtension,
pub exports_fields: Vec<Vec<String>>,
pub imports_fields: Vec<Vec<String>>,
pub extension_alias: Vec<(String, Vec<String>)>,
pub extensions: Vec<String>,
pub fallback: Alias,
pub fully_specified: bool,
pub main_fields: Vec<String>,
pub main_files: Vec<String>,
pub modules: Vec<String>,
pub resolve_to_context: bool,
pub prefer_relative: bool,
pub prefer_absolute: bool,
pub restrictions: Vec<Restriction>,
pub roots: Vec<PathBuf>,
pub symlinks: bool,
pub builtin_modules: bool,
}
Expand description
Module Resolution Options
Options are directly ported from enhanced-resolve.
See webpack resolve for information and examples
Fields§
§tsconfig: Option<TsconfigOptions>
Path to TypeScript configuration file.
Default None
alias: Alias
Create aliases to import or require certain modules more easily.
An alias is used to replace a whole path or part of a path.
For example, to alias a commonly used src/
folders: vec![("@/src"), vec![AliasValue::Path("/path/to/src")]]
A trailing $ can also be added to the given object’s keys to signify an exact match.
See webpack’s resolve.alias
documentation for a list of use cases.
alias_fields: Vec<Vec<String>>
A list of alias fields in description files.
Specify a field, such as browser
, to be parsed according to this specification.
Can be a path to json object such as ["path", "to", "exports"]
.
Default []
condition_names: Vec<String>
Condition names for exports field which defines entry points of a package.
The key order in the exports field is significant. During condition matching, earlier entries have higher priority and take precedence over later entries.
Default []
description_files: Vec<String>
The JSON files to use for descriptions. (There was once a bower.json
.)
Default ["package.json"]
enforce_extension: EnforceExtension
Set to EnforceExtension::Enabled for ESM Mandatory file extensions.
If enforce_extension
is set to EnforceExtension::Enabled, resolution will not allow extension-less files.
This means require('./foo.js')
will resolve, while require('./foo')
will not.
The default value for enforce_extension
is EnforceExtension::Auto, which is changed upon initialization.
It changes to EnforceExtension::Enabled if ResolveOptions::extensions contains an empty string; otherwise, this value changes to EnforceExtension::Disabled.
Explicitly set the value to EnforceExtension::Disabled to disable this automatic behavior.
For reference, this behavior is aligned with enhanced-resolve
. See https://github.com/webpack/enhanced-resolve/pull/285.
exports_fields: Vec<Vec<String>>
A list of exports fields in description files.
Can be a path to a JSON object such as ["path", "to", "exports"]
.
Default [["exports"]]
.
imports_fields: Vec<Vec<String>>
Fields from package.json
which are used to provide the internal requests of a package
(requests starting with # are considered internal).
Can be a path to a JSON object such as ["path", "to", "imports"]
.
Default [["imports"]]
.
extension_alias: Vec<(String, Vec<String>)>
An object which maps extension to extension aliases.
Default {}
extensions: Vec<String>
Attempt to resolve these extensions in order.
If multiple files share the same name but have different extensions, will resolve the one with the extension listed first in the array and skip the rest.
All extensions must have a leading dot.
Default [".js", ".json", ".node"]
fallback: Alias
Redirect module requests when normal resolving fails.
Default []
fully_specified: bool
Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests).
See also webpack configuration resolve.fullySpecified
Default false
main_fields: Vec<String>
A list of main fields in description files
Default ["main"]
.
main_files: Vec<String>
The filename to be used while resolving directories.
Default ["index"]
modules: Vec<String>
A list of directories to resolve modules from, can be absolute path or folder name.
Default ["node_modules"]
resolve_to_context: bool
Resolve to a context instead of a file.
Default false
prefer_relative: bool
Prefer to resolve module requests as relative requests instead of using modules from node_modules directories.
Default false
prefer_absolute: bool
Prefer to resolve server-relative urls as absolute paths before falling back to resolve in ResolveOptions::roots.
Default false
restrictions: Vec<Restriction>
A list of resolve restrictions to restrict the paths that a request can be resolved on.
Default []
roots: Vec<PathBuf>
A list of directories where requests of server-relative URLs (starting with ‘/’) are resolved. On non-Windows systems these requests are resolved as an absolute path first.
Default []
symlinks: bool
Whether to resolve symlinks to their symlinked location. When enabled, symlinked resources are resolved to their real path, not their symlinked location. Note that this may cause module resolution to fail when using tools that symlink packages (like npm link).
Default true
builtin_modules: bool
Whether to parse module.builtinModules or not. For example, “zlib” will throw crate::ResolveError::Builtin when set to true.
Default false
Implementations§
source§impl ResolveOptions
impl ResolveOptions
sourcepub fn with_condition_names(self, names: &[&str]) -> Self
pub fn with_condition_names(self, names: &[&str]) -> Self
§Examples
use oxc_resolver::ResolveOptions;
let options = ResolveOptions::default().with_condition_names(&["bar"]);
assert_eq!(options.condition_names, vec!["bar".to_string()])
sourcepub fn with_builtin_modules(self, flag: bool) -> Self
pub fn with_builtin_modules(self, flag: bool) -> Self
§Examples
use oxc_resolver::ResolveOptions;
let options = ResolveOptions::default().with_builtin_modules(false);
assert_eq!(options.builtin_modules, false)
sourcepub fn with_root<P: AsRef<Path>>(self, root: P) -> Self
pub fn with_root<P: AsRef<Path>>(self, root: P) -> Self
Adds a single root to the options
§Examples
use oxc_resolver::ResolveOptions;
use std::path::{Path, PathBuf};
let options = ResolveOptions::default().with_root("foo");
assert_eq!(options.roots, vec![PathBuf::from("foo")])
sourcepub fn with_extension<S: Into<String>>(self, extension: S) -> Self
pub fn with_extension<S: Into<String>>(self, extension: S) -> Self
Adds a single extension to the list of extensions
§Examples
use oxc_resolver::ResolveOptions;
use std::path::{Path, PathBuf};
let options = ResolveOptions::default().with_extension("jsonc");
assert!(options.extensions.contains(&"jsonc".to_string()));
sourcepub fn with_main_field<S: Into<String>>(self, field: S) -> Self
pub fn with_main_field<S: Into<String>>(self, field: S) -> Self
Adds a single main field to the list of fields
§Examples
use oxc_resolver::ResolveOptions;
use std::path::{Path, PathBuf};
let options = ResolveOptions::default().with_main_field("something");
assert!(options.main_fields.contains(&"something".to_string()));
sourcepub fn with_force_extension(self, enforce_extension: EnforceExtension) -> Self
pub fn with_force_extension(self, enforce_extension: EnforceExtension) -> Self
Changes how the extension should be treated
§Examples
use oxc_resolver::{ResolveOptions, EnforceExtension};
use std::path::{Path, PathBuf};
let options = ResolveOptions::default().with_force_extension(EnforceExtension::Enabled);
assert_eq!(options.enforce_extension, EnforceExtension::Enabled);
sourcepub fn with_fully_specified(self, fully_specified: bool) -> Self
pub fn with_fully_specified(self, fully_specified: bool) -> Self
Sets the value for ResolveOptions::fully_specified
§Examples
use oxc_resolver::{ResolveOptions};
use std::path::{Path, PathBuf};
let options = ResolveOptions::default().with_fully_specified(true);
assert_eq!(options.fully_specified, true);
sourcepub fn with_prefer_relative(self, flag: bool) -> Self
pub fn with_prefer_relative(self, flag: bool) -> Self
Sets the value for ResolveOptions::prefer_relative
§Examples
use oxc_resolver::{ResolveOptions};
use std::path::{Path, PathBuf};
let options = ResolveOptions::default().with_prefer_relative(true);
assert_eq!(options.prefer_relative, true);
sourcepub fn with_prefer_absolute(self, flag: bool) -> Self
pub fn with_prefer_absolute(self, flag: bool) -> Self
Sets the value for ResolveOptions::prefer_absolute
§Examples
use oxc_resolver::{ResolveOptions};
use std::path::{Path, PathBuf};
let options = ResolveOptions::default().with_prefer_absolute(true);
assert_eq!(options.prefer_absolute, true);
sourcepub fn with_symbolic_link(self, flag: bool) -> Self
pub fn with_symbolic_link(self, flag: bool) -> Self
Changes the value of ResolveOptions::symlinks
§Examples
use oxc_resolver::{ResolveOptions};
let options = ResolveOptions::default().with_symbolic_link(false);
assert_eq!(options.symlinks, false);
sourcepub fn with_module<M: Into<String>>(self, module: M) -> Self
pub fn with_module<M: Into<String>>(self, module: M) -> Self
Adds a module to ResolveOptions::modules
§Examples
use oxc_resolver::{ResolveOptions};
let options = ResolveOptions::default().with_module("module");
assert!(options.modules.contains(&"module".to_string()));
sourcepub fn with_main_file<M: Into<String>>(self, module: M) -> Self
pub fn with_main_file<M: Into<String>>(self, module: M) -> Self
Adds a main file to ResolveOptions::main_files
§Examples
use oxc_resolver::{ResolveOptions};
let options = ResolveOptions::default().with_main_file("foo");
assert!(options.main_files.contains(&"foo".to_string()));
Trait Implementations§
source§impl Clone for ResolveOptions
impl Clone for ResolveOptions
source§fn clone(&self) -> ResolveOptions
fn clone(&self) -> ResolveOptions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ResolveOptions
impl Debug for ResolveOptions
source§impl Default for ResolveOptions
impl Default for ResolveOptions
Auto Trait Implementations§
impl Freeze for ResolveOptions
impl RefUnwindSafe for ResolveOptions
impl Send for ResolveOptions
impl Sync for ResolveOptions
impl Unpin for ResolveOptions
impl UnwindSafe for ResolveOptions
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)