Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/vite_js_runtime/src/providers/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ fn calculate_expires_at(max_age: Option<u64>) -> u64 {

/// Get the Node.js distribution base URL
///
/// Returns the value of `VITE_NODE_DIST_MIRROR` environment variable if set,
/// Returns the value of `VP_NODE_DIST_MIRROR` environment variable if set,
/// otherwise returns the default `https://nodejs.org/dist`.
fn get_dist_url() -> Str {
vite_shared::EnvConfig::get().node_dist_mirror.map_or_else(
Expand Down
4 changes: 2 additions & 2 deletions crates/vite_shared/src/env_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct EnvConfig {

/// Node.js distribution mirror URL.
///
/// Env: `VITE_NODE_DIST_MIRROR`
/// Env: `VP_NODE_DIST_MIRROR`
pub node_dist_mirror: Option<String>,

/// Whether running in a CI environment.
Expand Down Expand Up @@ -136,7 +136,7 @@ impl EnvConfig {
.unwrap_or_else(|_| "https://registry.npmjs.org".into())
.trim_end_matches('/')
.to_string(),
node_dist_mirror: std::env::var(env_vars::VITE_NODE_DIST_MIRROR).ok(),
node_dist_mirror: std::env::var(env_vars::VP_NODE_DIST_MIRROR).ok(),
is_ci: std::env::var("CI").is_ok(),
bypass_shim: std::env::var(env_vars::VP_BYPASS).is_ok(),
debug_shim: std::env::var(env_vars::VP_DEBUG_SHIM).is_ok(),
Expand Down
2 changes: 1 addition & 1 deletion crates/vite_shared/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const NPM_CONFIG_REGISTRY: &str = "npm_config_registry";
pub const NPM_CONFIG_REGISTRY_UPPER: &str = "NPM_CONFIG_REGISTRY";

/// Node.js distribution mirror URL for downloads.
pub const VITE_NODE_DIST_MIRROR: &str = "VITE_NODE_DIST_MIRROR";
pub const VP_NODE_DIST_MIRROR: &str = "VP_NODE_DIST_MIRROR";

/// Override Node.js version (takes highest priority in version resolution).
pub const VP_NODE_VERSION: &str = "VP_NODE_VERSION";
Expand Down
15 changes: 15 additions & 0 deletions docs/guide/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,18 @@ vp env list-remote --lts # List only LTS versions
vp env exec --node lts npm i # Execute npm with latest LTS
vp env exec node -v # Use shim mode with automatic version resolution
```

## Custom Node.js Mirror

By default, Vite+ downloads Node.js from `https://nodejs.org/dist`. If you're behind a corporate proxy or need to use an internal mirror (e.g., Artifactory), set the `VP_NODE_DIST_MIRROR` environment variable:

```bash
# Install a specific version from your custom mirror
VP_NODE_DIST_MIRROR=https://my-mirror.example.com/nodejs/dist vp env install 22

# Set the global default version using a custom mirror
VP_NODE_DIST_MIRROR=https://my-mirror.example.com/nodejs/dist vp env default lts

# Set it permanently in your shell profile (.bashrc, .zshrc, etc.)
echo 'export VP_NODE_DIST_MIRROR=https://my-mirror.example.com/nodejs/dist' >> ~/.zshrc
```
6 changes: 3 additions & 3 deletions rfcs/js-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ https://nodejs.org/dist/v{version}/node-v{version}-{platform}.{ext}

### Custom Mirror Support

The distribution URL can be overridden using the `VITE_NODE_DIST_MIRROR` environment variable. This is useful for corporate environments or regions where nodejs.org might be slow or blocked.
The distribution URL can be overridden using the `VP_NODE_DIST_MIRROR` environment variable. This is useful for corporate environments or regions where nodejs.org might be slow or blocked.

```bash
VITE_NODE_DIST_MIRROR=https://example.com/mirrors/node vp build
VP_NODE_DIST_MIRROR=https://example.com/mirrors/node vp build
```

The mirror URL should have the same directory structure as the official distribution. Trailing slashes are automatically trimmed.
Expand Down Expand Up @@ -680,7 +680,7 @@ pub enum Error {
4. ✅ Handles concurrent downloads safely
5. ✅ Returns version and binary path
6. ✅ Comprehensive test coverage
7. ✅ Custom mirrors via `VITE_NODE_DIST_MIRROR` environment variable
7. ✅ Custom mirrors via `VP_NODE_DIST_MIRROR` environment variable
8. ✅ Support `devEngines.runtime` from package.json
9. ✅ Support semver ranges (^, ~, etc.) with version resolution
10. ✅ Version index caching with 1-hour TTL
Expand Down
Loading