# How to use npm run dev with DDEV in container ?

**URL:** https://discourse.roots.io/t/how-to-use-npm-run-dev-with-ddev-in-container/30060
**Category:** vite
**Tags:** vite, ddev, sage11
**Created:** 2025-11-29T00:20:35Z
**Posts:** 4

## Post 1 by @Othy545 — 2025-11-29T00:20:35Z

Hello everyone !

Has anyone here ever managed to run `npm run dev` successfully with DDEV? When I run it outside the container it works fine, but when I run it inside DDEV, the CSS and JS aren’t loading and, of course, there is no hot reload.

---

## Post 2 by @JacobBlana — 2025-11-29T23:26:23Z

Add this to .ddev/config.yaml, tweak vite.config and then run it with `ddev npm run dev`

```
web_extra_exposed_ports:
  - name: vite
    container_port: 5173
    http_port: 5172
    https_port: 5173
```

```
// Adjust Vites dev server for DDEV
  // https://vitejs.dev/config/server-options.html
  server: {
    // Respond to all network requests
    host: "0.0.0.0",
    port: 5173,
    strictPort: true,
    // Defines the origin of the generated asset URLs during development,
    // this must be set to the Vite dev server URL and selected port.
    origin: `${process.env.DDEV_PRIMARY_URL_WITHOUT_PORT}:5173`,
    // Configure CORS securely for the Vite dev server to allow requests
    // from *.ddev.site domains, supports additional hostnames (via regex).
    // If you use another `project_tld`, adjust this value accordingly.
    cors: {
      origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/,
    },
  }
```

All of this is written in this article [Working with Vite in DDEV - an introduction | DDEV](https://ddev.com/blog/working-with-vite-in-ddev/)

---

## Post 3 by @Othy545 — 2025-11-30T17:51:15Z

Ah yes its works the only thing i didn’t do is the cors  
This should be added to docs

Thanks !

---

## Post 4 by @Othy545 — 2025-11-30T17:54:01Z

Oh one more thing

How can I expose correctly to be able to dev on mobile ?
