Closed dominikkrulak closed 1 year ago
Yeah you shouldn't really need to ever use
{% if craft.vite.devServerRunning() %}
...in Twig. The plugin will do the right thing and use the devServer in local dev if it is running, and if not, use the production build.
Have a look at how it is done here as well: https://github.com/nystudio107/devmode
Thanks Andrew!
Question
I installed Craft Vite plugin for the first time and set stuff up in my Docker environment. Got it working after a while because I though that to use
checkDevServer
setting inconfig.php
file must be set totrue
.Because of that I couldn't start my Vite dev server using
{{ craft.vite.script("src/ts/main.ts") }}
. Accessing file using hard-coded server link like<script type="module" src="https://localhost:3000/src/ts/main.ts"></script>
worked and I though hmm.Going through your code I found that setting
'checkDevServer' => true
causes to proceed further down to pingdevServerInternal
which in my case is empty string and that makesdevServerRunning()
function to returnfalse
. That caused a cascade of outputs that caused my problem.So in my
dev
mode I had my{{ craft.vite.script("src/ts/main.ts") }}
twig code that generatedscript
for production and I couldn't get in my browser's console[vite] connected.
.My question Andrew is (which seems now quiet obvious)
checkDevServer
setting meant fordevServerInternal
setting for example you described in your documentation about using DDEV?