Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

DDEV addon: Adds configuration file to expose the standard vite 3 port in DDEV

License

Notifications You must be signed in to change notification settings

mandrasch/ddev-addon-simple-vite

Repository files navigation

This add-on is not needed anymore / not maintained anymore

You can now just expose ports via .ddev/config.yaml, no need to use a docker-compose file anymore:

nodejs_version: "18"
# Expose vite port
web_extra_exposed_ports:
  - name: node-vite
    container_port: 5173
    http_port: 5172
    https_port: 5173

See for more information:








tests project is maintained

ddev-simple-vite (DDEV addon)

🚧 Work in progress 🚧

Simple DDEV addon for Vite 3 / Vite 2.

Install it via:

ddev get mandrasch/ddev-addon-simple-vite
ddev restart

Adds docker-compose.simple-vite.yaml to your .ddev folder. This file takes care of exposing vites port through DDEV router (reverse proxy) so that it can be accessed via https://<your-project-name>.ddev.site:5173. See DDEV docs for more information.

ℹ️ For a more extended approach see torenware/ddev-viteserve.

Vite 3

Vite 3 configuration

After installing this addon you need to use the following vite.config.js-settings for server:{}:

// ...
export default defineConfig({
  // ...
  server: {
      // respond to all network requests
      host: '0.0.0.0',
      strictPort: true,
      port: 5173
  }
});

PHP frontend configuration

Start vite via ddev exec npm run dev as usual (ddev exec npm install is needed beforehand of course. 😉).

Your PHP framework needs to point to the following vite url in local development:

https://<your-project-name>.ddev.site:5173

The HTML output in local development should be like

<script type="module" src="https://<your-project-name>.ddev.site:5173/@vite/client"></script>

Every PHP framework (or framework plugin) does this slightly different, some even need some custom adjustments or may not be currently capable to do this out of the box. Check your browsers developer tools console / network tab for errors.

Example repositories / projects:

Resources for various PHP frameworks:

Vite 2

Vite 2 configuration

You need to use the same server:{}-config as above in vite.config.js. The default port of Vite 2 is 3000. Either change it in vite.config.js to 5173:

// ...
export default defineConfig({
  // ...
  server: {
      // respond to all network requests
      host: '0.0.0.0',
      strictPort: true,
      port: 5173
  }
});

Or change the docker-compose.vite-simple.yaml file like this if you want to use 3000 (needs a ddev restart):

#ddev-generated
# Expose vites port to DDEV router / docker for outside access
version: '3.6'
services:
  web:
    expose:
      - '3000'
    environment:
      - HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILHOG_PORT}:8025,3001:3000
      - HTTPS_EXPOSE=${DDEV_ROUTER_HTTPS_PORT}:80,${DDEV_MAILHOG_HTTPS_PORT}:8025,3000:3000

PHP frontend configuration

See above, same as Vite 3.

Acknowledgements

Thanks to @rfay, @torenware, @tyler36 (and others) for taking the time to discuss this approach in torenware/ddev-viteserve/issues/2!

Other approaches

License and credits

Created via https://github.com/drud/ddev-addon-template, addon is licensed as Apache License 2.0 (Open Source) as well.

See My DDEV lab for more DDEV-related information.

About

DDEV addon: Adds configuration file to expose the standard vite 3 port in DDEV

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages