nystudio107 / craft-plugin-vite

Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support
MIT License
12 stars 11 forks source link

Is `checkDevServer` setting meant for `devServerInternal` setting? #15

Closed dominikkrulak closed 1 year ago

dominikkrulak commented 1 year ago

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

{% if craft.vite.devServerRunning() %}
   <base href="{{ alias('@viteBaseUrl') }}">
{% endif %}

checkDevServer setting in config.php file must be set to true.

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 ping devServerInternal which in my case is empty string and that makes devServerRunning() function to return false. 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 generated script 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 for devServerInternal setting for example you described in your documentation about using DDEV?

khalwat commented 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

dominikkrulak commented 1 year ago

Thanks Andrew!