Vite Integration¶
Vite is a popular front-end build tool that provides fast development server with Hot Module Replacement (HMR) and optimized production builds. DDEV supports Vite development workflows for various frameworks including Laravel, Vue.js, React, Svelte, and more.
Quick Setup¶
To use Vite with DDEV, you need to:
-
Configure DDEV to expose Vite’s port in
.ddev/config.yaml
: -
Configure Vite in your
vite.config.js
:import { defineConfig } from 'vite' export default defineConfig({ 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+)?$/, }, }, })
-
Restart DDEV to apply configuration changes:
-
Start Vite development server:
Your Vite development server will be available at https://yourproject.ddev.site:5173
.
HTTPS Configuration
This guide assumes your project runs on https://
. If you cannot access the HTTPS version of your project, see the DDEV installation documentation.
Custom TLD
If you use a custom project_tld
other than ddev.site
, adjust the CORS configuration accordingly in your vite.config.js
.
Framework-Specific Configuration¶
Laravel¶
Laravel includes Vite as the default asset bundler since v9.19. Here’s the recommended setup:
DDEV Configuration¶
Add to .ddev/config.yaml
:
Laravel Vite Configuration¶
Update your vite.config.js
:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: true,
}),
],
server: {
host: "0.0.0.0",
port: 5173,
strictPort: true,
origin: `${process.env.DDEV_PRIMARY_URL_WITHOUT_PORT}:5173`,
cors: {
origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/,
},
hmr: {
host: "localhost",
},
},
});
Usage in Blade Templates¶
In your Blade templates, use Laravel’s Vite directives:
Drupal¶
For Drupal projects using the Vite module:
Drupal DDEV Configuration¶
Drupal Vite Configuration¶
import { defineConfig } from 'vite'
export default defineConfig({
base: '/sites/default/files/vite/',
build: {
manifest: true,
outDir: 'sites/default/files/vite',
rollupOptions: {
input: {
main: 'assets/js/main.js',
style: 'assets/css/style.css',
}
}
},
server: {
host: "0.0.0.0",
port: 5173,
strictPort: true,
origin: `${process.env.DDEV_PRIMARY_URL_WITHOUT_PORT}:5173`,
cors: {
origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/,
},
},
})
TYPO3¶
For TYPO3 projects using vite-asset-collector:
TYPO3 DDEV Configuration¶
TYPO3 Vite Configuration¶
import { defineConfig } from 'vite'
export default defineConfig({
base: '/typo3temp/assets/vite/',
build: {
manifest: true,
outDir: 'public/typo3temp/assets/vite/',
rollupOptions: {
input: {
main: 'packages/site_package/Resources/Private/Assets/main.js',
}
}
},
server: {
host: "0.0.0.0",
port: 5173,
strictPort: true,
origin: `${process.env.DDEV_PRIMARY_URL_WITHOUT_PORT}:5173`,
cors: {
origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/,
},
},
})
WordPress¶
For WordPress projects using Vite with themes or plugins:
WordPress DDEV Configuration¶
WordPress Vite Configuration¶
import { defineConfig } from 'vite'
export default defineConfig({
base: '/wp-content/themes/your-theme/dist/',
build: {
manifest: true,
outDir: 'wp-content/themes/your-theme/dist',
rollupOptions: {
input: {
main: 'wp-content/themes/your-theme/src/main.js',
}
}
},
server: {
host: "0.0.0.0",
port: 5173,
strictPort: true,
origin: `${process.env.DDEV_PRIMARY_URL_WITHOUT_PORT}:5173`,
cors: {
origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/,
},
},
})
Craft CMS¶
For Craft CMS projects using nystudio107
’s Vite plugin:
Craft CMS DDEV Configuration¶
Craft CMS Vite Configuration¶
import { defineConfig } from 'vite'
export default defineConfig({
base: '/dist/',
build: {
manifest: true,
outDir: 'web/dist/',
rollupOptions: {
input: {
app: 'src/js/app.js',
}
}
},
server: {
host: "0.0.0.0",
port: 5173,
strictPort: true,
origin: `${process.env.DDEV_PRIMARY_URL_WITHOUT_PORT}:5173`,
cors: {
origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/,
},
fs: {
strict: false
}
},
})
Advanced Configuration¶
Auto-starting Vite¶
You can configure DDEV to automatically start Vite when the project starts using hooks:
Add to .ddev/config.yaml
:
Or use a more robust daemon configuration:
Production Builds¶
For production builds, ensure your vite.config.js
includes proper manifest generation:
export default defineConfig({
build: {
manifest: true,
rollupOptions: {
input: {
main: 'path/to/your/main.js',
}
}
},
// ... other configuration
})
Build for production:
DDEV Add-ons¶
Several community add-ons are available to simplify Vite integration:
-
ddev-vite-sidecar: Zero-config integration of Vite into DDEV projects. The Vite development server is exposed as a
https://vite.*
subdomain, eliminating the need to expose ports to the host system. -
ddev-vitest: Adds helper commands for projects using Vitest, a Vite-native testing framework.
Explore the DDEV Add-on Registry for more Vite-related add-ons.
GitHub Codespaces¶
When using DDEV with GitHub Codespaces, DDEV’s router is not used, so some adjustments are needed:
- Port exposure doesn’t work via
.ddev/config.yaml
- use a docker-compose file instead - Create
.ddev/docker-compose.vite-workaround.yaml
:
See the DDEV Codespaces documentation for more details.
Using with Node.js Projects¶
For Node.js-only projects (like SvelteKit, Nuxt, or Vue CLI projects):
Node.js DDEV Configuration¶
project_type: generic
webserver_type: generic
web_extra_exposed_ports:
- name: vite
container_port: 5173
http_port: 80
https_port: 443
web_extra_daemons:
- name: "vite-dev"
command: "npm run dev"
directory: /var/www/html
Node.js Vite Configuration¶
export default defineConfig({
server: {
host: "0.0.0.0",
port: 5173,
strictPort: true,
origin: `${process.env.DDEV_PRIMARY_URL_WITHOUT_PORT}:5173`,
cors: {
origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/,
},
},
})
Troubleshooting¶
Bad Gateway Errors¶
Problem: Getting “502 Bad Gateway” when accessing Vite URL.
Solutions:
-
Check port configuration: Ensure
web_extra_exposed_ports
is correctly configured in.ddev/config.yaml
. -
Verify Vite is running: Check if Vite development server is actually running:
-
Restart DDEV: After changing configuration:
CORS Issues¶
Problem: Browser console shows CORS errors.
Solutions:
-
Update CORS configuration in
vite.config.js
: -
Check origin setting:
Port Already in Use¶
Problem: “Port 5173 is already in use” error.
Solutions:
-
Use different port: Change the port in both DDEV and Vite configurations:
-
Kill existing process:
HMR Not Working¶
Problem: Hot Module Replacement isn’t working in the browser.
Solutions:
-
Check HMR configuration:
-
For Laravel projects, ensure you’re using the
@vite
directive in your Blade templates. -
Check browser console for WebSocket connection errors.
Assets Not Loading¶
Problem: CSS/JS assets not loading properly.
Solutions:
-
Verify base path in production builds matches your web server configuration.
-
Check manifest.json is being generated and loaded correctly.
-
Ensure proper asset URLs in your templates/framework integration.
Best Practices¶
-
Use specific Node.js versions: Specify
nodejs_version
in your DDEV configuration for consistency across team members. -
Include Vite in your project dependencies: Don’t rely on global Vite installations.
-
Configure proper
.gitignore
: Exclude build artifacts: -
Document your setup: Include Vite configuration instructions in your project’s readme.
-
Use environment variables: Leverage
process.env.DDEV_PRIMARY_URL
for dynamic configuration.
Additional Resources¶
WordPress Libraries¶
For WordPress projects, several libraries can help integrate Vite:
Example Repositories¶
Further Reading¶
- Node.js Development with DDEV - Comprehensive guide to Node.js workflows in DDEV
- How to Run Headless Drupal and Next.js on DDEV
- How we use DDEV, Vite and Tailwind with Craft CMS
- Integrating Vite and DDEV into WordPress