Question
I have spent hours pouring over all the documentation I can find, tweaking parameters, but cannot seem to get my Vite server running within my DDEV environment.
I have successfully run npm run dev
/ vite
both on local and within my container. However, any url of the form 127.0.0.1:3000/...
returns a 502, as does craft.ddev.site:3000/...
. This happens whether I load the url manually or through twig: {{ craft.vite.script("src/ts/index.ts") }}
. The markup generated by this tag seems to be correct: <script type="module" src="https://craft.ddev.site:3000/src/ts/index.ts"></script>
Also, I have confirmed through {{ craft.vite.devServerRunning() }}
that the dev server is running, though if i make 'checkDevServer' => true,
, the devServerRunning tag says that it's not. So not sure what to make of that. Anyway, below are my configs - let me know if something seems off, and Thanks!
vite.php
use craft\helpers\App;
return [
'useDevServer' => App::env('CRAFT_ENVIRONMENT') === 'dev',
'manifestPath' => '@webroot/dist/manifest.json',
'devServerPublic' => App::env('PRIMARY_SITE_URL') . ':3000',
'serverPublic' => App::env('PRIMARY_SITE_URL') . '/dist/',
'errorEntry' => '',
'cacheKeySuffix' => '',
'devServerInternal' => 'http://localhost:3000',
'checkDevServer' => false,
'includeReactRefreshShim' => false,
'includeModulePreloadShim' => true,
// 'criticalPath' => '@webroot/dist/criticalcss',
// 'criticalSuffix' =>'_critical.min.css',
];
vite.config.js
export default ({ command }) => ({
base: command === 'serve' ? '' : '/dist/',
build: {
cssCodeSplit: false,
emptyOutDir: true,
manifest: true,
outDir: './web/dist/',
rollupOptions: {
input: {
app: './src/ts/index.ts',
},
output: {
sourcemap: true,
},
},
},
plugins: [
ViteRestart({
restart: [
'./templates/**/*',
],
}),
mkcert(),
],
server: {
host: '0.0.0.0',
port: 3000,
https: true,
},
css: {
postcss: postcssConfig,
},
});
docker-compose.vite.yaml
version: '3.6'
services:
web:
ports:
- '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
src/ts/index.ts
import Alpine from 'alpinejs'
import '../css/index.css'
if (import.meta.hot) {
import.meta.hot.accept(() => {
console.log("HMR")
});
}
window.Alpine = Alpine
Alpine.start()
alert('hello world')
question