vite_rust

Struct ViteConfig

source
pub struct ViteConfig<'a> {
    pub manifest_path: &'a str,
    pub entrypoints: Option<Vec<&'a str>>,
    pub force_mode: Option<ViteMode>,
    pub use_heart_beat_check: bool,
    pub enable_dev_server: bool,
    pub server_host: Option<&'a str>,
}

Fields§

§manifest_path: &'a str

The path/to/manifest.json file. Currently, Vite won’t resolve relative paths, so please consider your current working directory as the root of it and start the path with a root node directory directly.

Optionally and experimentally, you can use the [resolve_path] method for the manifest file resolution. However, this method might come to fail at some point, and will also panic in the many situations described on its documentation.

§Example

your_project/
|-- public/
|   |-- dist/
|   |   |-- manifest.json
|-- src/
|   |-- main.rs // <-- you're here!
 
use vite_rust::{ViteConfig, utils::resolve_path};
 
let config = ViteConfig {
    manifest_path: "public/dist/manifest.json",
    // or
    manifest_path: resolve_path(file!(), "../public/dist/manifest.json"),
    // ...
};
§entrypoints: Option<Vec<&'a str>>

Defines which entrypoints Vite will use to generate the html script, link and stylesheet tags.

If None is provided, Vite will scan the manifest for files with isEntry: true property and consider them the entrypoints.

§force_mode: Option<ViteMode>

If None is provided, Vite will discover which one to use considering:

  • any of RUST_ENV, NODE_ENV or APP_ENV environment variables exists and is set to true;
  • Dev-server is running;
  • Heart beat check is enabled.

By setting this option, the discovering phase will be skipped. Refer to the crate’s README.md file to understand the way it decides which mode to pick.

§use_heart_beat_check: bool

Whether Vite should ping your vite dev-server to check if its running. If false, ViteMode will be set to Development if not forced by the configuration.

§enable_dev_server: bool

Whether dev server should be considered or not.

If false, force_mode should be either Manifest or None, otherwise, undefined behavior might occur.

§server_host: Option<&'a str>

The host in which your vite dev-server is running. Normally, it would be "http://localhost:5173".

Please, do not forget the protocol (http, https)!

Implementations§

source§

impl<'a> ViteConfig<'a>

source

pub fn new_with_defaults(manifest_path: &'a str) -> Self

Create a ViteConfig instance.

You can create your config by directly instantiating the struct, or by using some default options and defining only the most critical fields:

§Example
use vite_rust::ViteConfig;
 
let manual_config = ViteConfig {
    manifest_path: "path/to/manifest.json",
    entrypoints: None, // Vite can discover them by itself
    force_mode: None, // Vite can discover it too
    use_heart_beat_check: true,
    enable_dev_server: true,
    server_host: Some("http://localhost:5173")
};
 
let with_defaults_config = ViteConfig::new_with_defaults("path/to/manifest.json");
 
assert_eq!(manual_config, with_defaults_config);

Trait Implementations§

source§

impl<'a> Debug for ViteConfig<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for ViteConfig<'a>

source§

fn eq(&self, other: &ViteConfig<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for ViteConfig<'a>

source§

impl<'a> StructuralPartialEq for ViteConfig<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ViteConfig<'a>

§

impl<'a> RefUnwindSafe for ViteConfig<'a>

§

impl<'a> Send for ViteConfig<'a>

§

impl<'a> Sync for ViteConfig<'a>

§

impl<'a> Unpin for ViteConfig<'a>

§

impl<'a> UnwindSafe for ViteConfig<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more