# JavaScriptHostingExtensions Methods

- Package: [Aspire.Hosting.JavaScript](/reference/api/csharp/aspire.hosting.javascript.md)
- Type: [JavaScriptHostingExtensions](/reference/api/csharp/aspire.hosting.javascript/javascripthostingextensions.md)
- Kind: `Methods`
- Members: `18`

Provides extension methods for adding JavaScript applications to an `Hosting.IDistributedApplicationBuilder`.

## AddBunApp(IDistributedApplicationBuilder, string, string, string)

- Name: `AddBunApp(IDistributedApplicationBuilder, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<BunAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L381-L626)

Adds a Bun application to the application model. Bun should be available on the PATH.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<BunAppResource> AddBunApp(
        this IDistributedApplicationBuilder builder,
        string name,
        string appDirectory,
        string scriptPath)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder` to add the resource to.
- `name` (`string`)
  The name of the resource.
- `appDirectory` (`string`)
  The path to the directory containing the Bun application.
- `scriptPath` (`string`)
  The path to the script (for example, `server.ts`) relative to `appDirectory` to run.

## Returns

`IResourceBuilder<BunAppResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This method executes the script directly using `bun <script>`. Bun natively runs JavaScript and TypeScript files so no transpile step is required. If the application directory contains a `package.json` file, Bun will be added as the default package manager. When publishing to a container, the default base image is `oven/bun:1` for both the build and runtime stages.

## Examples

Add a Bun app to the application model:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddBunApp("api", "../api", "server.ts");

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddJavaScriptApp(IDistributedApplicationBuilder, string, string, string)

- Name: `AddJavaScriptApp(IDistributedApplicationBuilder, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<JavaScriptAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L691-L699)

Adds a JavaScript application resource to the distributed application using the specified app directory and run script.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<JavaScriptAppResource> AddJavaScriptApp(
        this IDistributedApplicationBuilder builder,
        string name,
        string appDirectory,
        string runScriptName = "dev")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The distributed application builder to which the JavaScript application resource will be added.
- `name` (`string`)
  The unique name of the JavaScript application resource. Cannot be null or empty.
- `appDirectory` (`string`)
  The path to the directory containing the JavaScript application.
- `runScriptName` (`string`) `optional`
  The name of the npm script to run when starting the application. Defaults to "dev". Cannot be null or empty.

## Returns

`IResourceBuilder<JavaScriptAppResource>` -- A resource builder for the newly added JavaScript application resource.

## Remarks

If a Dockerfile does not exist in the application's directory, one will be generated automatically when publishing. The method configures the resource with Node.js defaults and sets up npm integration.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddNextJsApp(IDistributedApplicationBuilder, string, string, string)

> **Experimental:** ASPIREJAVASCRIPT001 - [Learn more](/diagnostics/aspirejavascript001/)

- Name: `AddNextJsApp(IDistributedApplicationBuilder, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<NextJsAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1540-L1609)

Adds a Next.js app to the distributed application builder.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<NextJsAppResource> AddNextJsApp(
        this IDistributedApplicationBuilder builder,
        string name,
        string appDirectory,
        string runScriptName = "dev")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder` to add the resource to.
- `name` (`string`)
  The name of the Next.js app.
- `appDirectory` (`string`)
  The path to the directory containing the Next.js app.
- `runScriptName` (`string`) `optional`
  The name of the script that runs the Next.js dev server. Defaults to "dev".

## Returns

`IResourceBuilder<NextJsAppResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This method configures the Next.js application for both local development and publishing. In run mode, it starts the Next.js dev server with the correct port binding. In publish mode, it generates a multi-stage Dockerfile using Next.js standalone output mode, which copies `public/`, `.next/standalone/`, and `.next/static/` into a Node.js runtime container.

The Next.js application must have `output: "standalone"` configured in `next.config.ts` and a `public/` directory (even if empty) for the published container to build correctly.

The following example creates a Next.js app.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddNextJsApp("frontend", "./frontend");

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddNodeApp(IDistributedApplicationBuilder, string, string, string)

- Name: `AddNodeApp(IDistributedApplicationBuilder, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<NodeAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L123-L286)

Adds a node application to the application model. Node should be available on the PATH.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<NodeAppResource> AddNodeApp(
        this IDistributedApplicationBuilder builder,
        string name,
        string appDirectory,
        string scriptPath)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder` to add the resource to.
- `name` (`string`)
  The name of the resource.
- `appDirectory` (`string`)
  The path to the directory containing the node application.
- `scriptPath` (`string`)
  The path to the script relative to the app directory to run.

## Returns

`IResourceBuilder<NodeAppResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This method executes a Node script directly using `node script.js`. If you want to use a package manager you can add one and configure the install and run scripts using the provided extension methods. If the application directory contains a `package.json` file, npm will be added as the default package manager.

## Examples

Add a Node app to the application model using yarn and 'yarn run dev' for running during development:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddNodeApp("frontend", "../frontend", "app.js")
       .WithYarn()
       .WithRunScript("dev");

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddViteApp(IDistributedApplicationBuilder, string, string, string)

- Name: `AddViteApp(IDistributedApplicationBuilder, string, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ViteAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1362-L1501)

Adds a Vite app to the distributed application builder.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<ViteAppResource> AddViteApp(
        this IDistributedApplicationBuilder builder,
        string name,
        string appDirectory,
        string runScriptName = "dev")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder` to add the resource to.
- `name` (`string`)
  The name of the Vite app.
- `appDirectory` (`string`)
  The path to the directory containing the Vite app.
- `runScriptName` (`string`) `optional`
  The name of the script that runs the Vite app. Defaults to "dev".

## Returns

`IResourceBuilder<ViteAppResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

The following example creates a Vite app using npm as the package manager.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddViteApp("frontend", "./frontend");

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## DisableBuildValidation(IResourceBuilder<NextJsAppResource>)

> **Experimental:** ASPIREJAVASCRIPT001 - [Learn more](/diagnostics/aspirejavascript001/)

- Name: `DisableBuildValidation(IResourceBuilder<NextJsAppResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<NextJsAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1627)

Disables deploy-time build validation checks for the Next.js application.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<NextJsAppResource> DisableBuildValidation(
        this IResourceBuilder<NextJsAppResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<NextJsAppResource>`)
  The resource builder.

## Returns

`IResourceBuilder<NextJsAppResource>` -- The resource builder for chaining.

## Remarks

By default, [JavaScriptHostingExtensions.AddNextJsApp(IDistributedApplicationBuilder, string, string, string)](/reference/api/csharp/aspire.hosting.javascript/javascripthostingextensions/methods.md#addnextjsapp-idistributedapplicationbuilder-string-string-string) adds publish prerequisite steps that verify the Next.js configuration (e.g. that `output: "standalone"` is set). Use this method to suppress those checks when the configuration is set dynamically or via an external mechanism that cannot be detected by static file inspection.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## PublishAsNodeServer(IResourceBuilder<TResource>, string, string)

> **Experimental:** ASPIREJAVASCRIPT001 - [Learn more](/diagnostics/aspirejavascript001/)

- Name: `PublishAsNodeServer(IResourceBuilder<TResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L908-L935)

Configures the JavaScript application to publish as a standalone Node.js server that runs a built artifact directly.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> PublishAsNodeServer<TResource>(
        this IResourceBuilder<TResource> builder,
        string entryPoint,
        string outputPath = ".")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<TResource>`)
  The JavaScript resource builder.
- `entryPoint` (`string`)
  The relative path to the Node.js entry point to execute in the published container after the build completes, such as `.output/server/index.mjs` or `build/index.js`.
- `outputPath` (`string`) `optional`
  The relative path containing the built runtime files to copy into the published container. Defaults to the application root.

## Returns

`IResourceBuilder<TResource>` -- The updated resource builder.

## Remarks

Use this method for frameworks that produce a Node.js server artifact during the build and recommend running that artifact directly in production rather than invoking a package manager script at runtime. The application source is still built using the configured package manager and build script; this method only changes the publish-time runtime container shape.

The container files source path is automatically set to `outputPath` so that only the built output directory is copied into the runtime container, not the full application source.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## PublishAsPackageScript(IResourceBuilder<TResource>, string, string?)

> **Experimental:** ASPIREJAVASCRIPT001 - [Learn more](/diagnostics/aspirejavascript001/)

- Name: `PublishAsPackageScript(IResourceBuilder<TResource>, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L973-L998)

Configures the JavaScript application to publish as a Node.js server that uses a `package.json` script at runtime.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> PublishAsPackageScript<TResource>(
        this IResourceBuilder<TResource> builder,
        string scriptName = "start",
        string? runScriptArguments = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<TResource>`)
  The JavaScript resource builder.
- `scriptName` (`string`) `optional`
  The name of the `package.json` script to run in the published container. For example, `start` invokes the configured package manager's run command for the `start` script, such as `npm run start`, `pnpm run start`, `yarn run start`, or `bun run start`.
- `runScriptArguments` (`string?`) `optional`
  Optional arguments appended after the script name at runtime, such as `-- --port "$PORT"`.

## Returns

`IResourceBuilder<TResource>` -- The updated resource builder.

## Remarks

Use this method for frameworks where the production server depends on packages in `node_modules` at runtime. The resulting container includes the full application with production dependencies installed.

This method is appropriate for frameworks like Nuxt (where `useAsyncData` / `useFetch` requires the full Nitro environment), Remix (where `react-router-serve` is an npm dependency), and Astro SSR (where the built entry point imports unbundled `@astrojs/*` packages).

For frameworks that produce a self-contained server artifact that does not require `node_modules`, use [JavaScriptHostingExtensions.PublishAsNodeServer(IResourceBuilder<TResource>, string, string)](/reference/api/csharp/aspire.hosting.javascript/javascripthostingextensions/methods.md#publishasnodeserver-iresourcebuilder-tresource-string-string) instead for a smaller runtime image.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## PublishAsStaticWebsite(IResourceBuilder<TResource>, Action<PublishAsStaticWebsiteOptions>)

> **Experimental:** ASPIREJAVASCRIPT001 - [Learn more](/diagnostics/aspirejavascript001/)

- Name: `PublishAsStaticWebsite(IResourceBuilder<TResource>, Action<PublishAsStaticWebsiteOptions>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L722-L724)

Configures the JavaScript application to publish as a standalone static website served by YARP.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> PublishAsStaticWebsite<TResource>(
        this IResourceBuilder<TResource> builder,
        Action<PublishAsStaticWebsiteOptions>? configure = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<TResource>`)
  The JavaScript resource builder.
- `configure` (`Action<PublishAsStaticWebsiteOptions>`) `optional`
  Optional callback to configure [PublishAsStaticWebsiteOptions](/reference/api/csharp/aspire.hosting.javascript/publishasstaticwebsiteoptions.md).

## Returns

`IResourceBuilder<TResource>` -- The updated resource builder.

## Remarks

The published container uses a YARP reverse proxy image for static file serving. To add an API reverse-proxy, use the overload that accepts an `apiPath` and `apiTarget`.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## PublishAsStaticWebsite(IResourceBuilder<TResource>, string, IResourceBuilder<IResourceWithServiceDiscovery>, Action<PublishAsStaticWebsiteOptions>)

> **Experimental:** ASPIREJAVASCRIPT001 - [Learn more](/diagnostics/aspirejavascript001/)

- Name: `PublishAsStaticWebsite(IResourceBuilder<TResource>, string, IResourceBuilder<IResourceWithServiceDiscovery>, Action<PublishAsStaticWebsiteOptions>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L759-L762)

Configures the JavaScript application to publish as a standalone static website served by YARP, with an API reverse-proxy to the specified resource.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> PublishAsStaticWebsite<TResource>(
        this IResourceBuilder<TResource> builder,
        string apiPath,
        IResourceBuilder<IResourceWithServiceDiscovery> apiTarget,
        Action<PublishAsStaticWebsiteOptions>? configure = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<TResource>`)
  The JavaScript resource builder.
- `apiPath` (`string`)
  A path prefix to reverse-proxy to a backend API. For example, `/api` proxies all requests matching `/api/{"{**catch-all}"}` to the backend resource.
- `apiTarget` (`IResourceBuilder<IResourceWithServiceDiscovery>`)
  The backend resource to proxy API requests to. YARP uses service discovery to resolve the appropriate endpoint, preferring HTTPS when available.
- `configure` (`Action<PublishAsStaticWebsiteOptions>`) `optional`
  Optional callback to configure [PublishAsStaticWebsiteOptions](/reference/api/csharp/aspire.hosting.javascript/publishasstaticwebsiteoptions.md).

## Returns

`IResourceBuilder<TResource>` -- The updated resource builder.

## Remarks

The published container uses a YARP reverse proxy image for static file serving and API reverse-proxy. YARP natively supports HTTPS backends and service discovery, so API proxy requests work correctly across all deployment targets (Docker Compose, Azure App Service, etc.).

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithBrowserDebugger(IResourceBuilder<T>, string)

> **Experimental:** ASPIREEXTENSION001 - [Learn more](/diagnostics/aspireextension001/)

- Name: `WithBrowserDebugger(IResourceBuilder<T>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L2046-L2089)

Configures a browser debugger for the JavaScript application resource, enabling browser-based debugging through a child resource that launches when the parent application is ready.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<T> WithBrowserDebugger<T>(
        this IResourceBuilder<T> builder,
        string browser = "msedge")
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource builder for the JavaScript application.
- `browser` (`string`) `optional`
  The browser to use for debugging. Defaults to `"msedge"`. Supported values include `"msedge"` and `"chrome"`.

## Returns

`IResourceBuilder<T>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining additional configuration.

## Exceptions

- `InvalidOperationException` -- Thrown when the parent resource does not have an HTTP or HTTPS endpoint, or when the IDE extension does not support browser debugging.

## Remarks

This method creates a child `JavaScript.BrowserDebuggerResource` that waits for the parent JavaScript application to start, then launches a browser debug session targeting the parent's HTTP or HTTPS endpoint. The parent resource must have at least one HTTP or HTTPS endpoint configured.

## Examples

Add browser debugging to a JavaScript application:

```csharp
var builder = DistributedApplication.CreateBuilder(args);
builder.AddViteApp("frontend", "./frontend")
    .WithBrowserDebugger();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithBuildScript(IResourceBuilder<TResource>, string, string[]?)

- Name: `WithBuildScript(IResourceBuilder<TResource>, string, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1932)

Adds a build script annotation to the resource builder using the specified command-line arguments.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> WithBuildScript<TResource>(
        this IResourceBuilder<TResource> resource,
        string scriptName,
        string[]? args = null)
    {
        // ...
    }
}
```

## Parameters

- `resource` (`IResourceBuilder<TResource>`)
  The resource builder to which the build script annotation will be added.
- `scriptName` (`string`)
  The name of the script to be executed when the resource is built.
- `args` (`string[]?`) `optional`
  An array of command-line arguments to use for the build script.

## Returns

`IResourceBuilder<TResource>` -- The same resource builder instance with the build script annotation applied.

## Remarks

Use this method to specify custom build scripts for JavaScript application resources during deployment.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithBun(IResourceBuilder<TResource>, bool, string[]?)

- Name: `WithBun(IResourceBuilder<TResource>, bool, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1720-L1764)

Configures the JavaScript resource to use Bun as the package manager and optionally installs packages before the application starts.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> WithBun<TResource>(
        this IResourceBuilder<TResource> resource,
        bool install = true,
        string[]? installArgs = null)
    {
        // ...
    }
}
```

## Parameters

- `resource` (`IResourceBuilder<TResource>`)
  The JavaScript application resource builder.
- `install` (`bool`) `optional`
  When true (default), automatically installs packages before the application starts. When false, only sets the package manager annotation without creating an installer resource.
- `installArgs` (`string[]?`) `optional`
  Additional command-line arguments passed to "bun install". When null, defaults are applied based on publish mode and lockfile presence.

## Returns

`IResourceBuilder<TResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

Bun forwards script arguments without requiring the `--` command separator, so this method configures the resource to omit it. When publishing and a bun lockfile ( `bun.lock` or `bun.lockb`) is present, `--frozen-lockfile` is used by default. Publishing to a container requires Bun to be present in the build image. This method configures a Bun build image when one is not already specified. [JavaScriptHostingExtensions.PublishAsPackageScript(IResourceBuilder<TResource>, string, string?)](/reference/api/csharp/aspire.hosting.javascript/javascripthostingextensions/methods.md#publishaspackagescript-iresourcebuilder-tresource-string-string) also uses the Bun image for the runtime stage unless a custom runtime image is configured. To use a specific Bun version, configure a custom build image (for example, `oven/bun:<tag>`) using `ContainerResourceBuilderExtensions.WithDockerfileBaseImage`.

## Examples

Run a Vite app using Bun as the package manager:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddViteApp("frontend", "./frontend")
       .WithBun()
       .WithDockerfileBaseImage(buildImage: "oven/bun:latest"); // To use a specific Bun image

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithNpm(IResourceBuilder<TResource>, bool, string?, string[]?)

- Name: `WithNpm(IResourceBuilder<TResource>, bool, string?, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1670-L1686)

Configures the Node.js resource to use npm as the package manager and optionally installs packages before the application starts.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> WithNpm<TResource>(
        this IResourceBuilder<TResource> resource,
        bool install = true,
        string? installCommand = null,
        string[]? installArgs = null)
    {
        // ...
    }
}
```

## Parameters

- `resource` (`IResourceBuilder<TResource>`)
  The NodeAppResource.
- `install` (`bool`) `optional`
  When true (default), automatically installs packages before the application starts. When false, only sets the package manager annotation without creating an installer resource.
- `installCommand` (`string?`) `optional`
  The install command itself passed to npm to install dependencies.
- `installArgs` (`string[]?`) `optional`
  The command-line arguments passed to npm to install dependencies.

## Returns

`IResourceBuilder<TResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithPnpm(IResourceBuilder<TResource>, bool, string[]?)

- Name: `WithPnpm(IResourceBuilder<TResource>, bool, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1868-L1909)

Configures the Node.js resource to use pnpm as the package manager and optionally installs packages before the application starts.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> WithPnpm<TResource>(
        this IResourceBuilder<TResource> resource,
        bool install = true,
        string[]? installArgs = null)
    {
        // ...
    }
}
```

## Parameters

- `resource` (`IResourceBuilder<TResource>`)
  The NodeAppResource.
- `install` (`bool`) `optional`
  When true (default), automatically installs packages before the application starts. When false, only sets the package manager annotation without creating an installer resource.
- `installArgs` (`string[]?`) `optional`
  The command-line arguments passed to "pnpm install".

## Returns

`IResourceBuilder<TResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithRunScript(IResourceBuilder<TResource>, string, string[]?)

- Name: `WithRunScript(IResourceBuilder<TResource>, string, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1951)

Adds a run script annotation to the specified JavaScript application resource builder, specifying the script to execute and its arguments during run mode.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> WithRunScript<TResource>(
        this IResourceBuilder<TResource> resource,
        string scriptName,
        string[]? args = null)
    {
        // ...
    }
}
```

## Parameters

- `resource` (`IResourceBuilder<TResource>`)
  The resource builder to which the run script annotation will be added.
- `scriptName` (`string`)
  The name of the script to be executed when the resource is run.
- `args` (`string[]?`) `optional`
  An array of arguments to pass to the script.

## Returns

`IResourceBuilder<TResource>` -- The same resource builder instance with the run script annotation applied, enabling further configuration.

## Remarks

Use this method to specify a custom script and its arguments that should be executed when the resource is executed in RunMode.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithViteConfig(IResourceBuilder<ViteAppResource>, string)

- Name: `WithViteConfig(IResourceBuilder<ViteAppResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ViteAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1650-L1655)

Configures the Vite app to use the specified Vite configuration file instead of the default resolution behavior.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<ViteAppResource> WithViteConfig(
        this IResourceBuilder<ViteAppResource> builder,
        string configPath)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<ViteAppResource>`)
  The resource builder.
- `configPath` (`string`)
  The path to the Vite configuration file. Relative to the Vite service project root.

## Returns

`IResourceBuilder<ViteAppResource>` -- The resource builder.

## Remarks

Use this method to specify a specific Vite configuration file if you need to override the default Vite configuration resolution behavior.

## Examples

Use a custom Vite configuration file:

```csharp
var builder = DistributedApplication.CreateBuilder(args);
var viteApp = builder.AddViteApp("frontend", "./frontend")
    .WithViteConfig("./vite.production.config.js");
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithYarn(IResourceBuilder<TResource>, bool, string[]?)

- Name: `WithYarn(IResourceBuilder<TResource>, bool, string[]?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<TResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L1789-L1832)

Configures the Node.js resource to use yarn as the package manager and optionally installs packages before the application starts.

```csharp
public static class JavaScriptHostingExtensions
{
    public static IResourceBuilder<TResource> WithYarn<TResource>(
        this IResourceBuilder<TResource> resource,
        bool install = true,
        string[]? installArgs = null)
    {
        // ...
    }
}
```

## Parameters

- `resource` (`IResourceBuilder<TResource>`)
  The NodeAppResource.
- `install` (`bool`) `optional`
  When true (default), automatically installs packages before the application starts. When false, only sets the package manager annotation without creating an installer resource.
- `installArgs` (`string[]?`) `optional`
  The command-line arguments passed to "yarn install".

## Returns

`IResourceBuilder<TResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
