django-vite icon indicating copy to clipboard operation
django-vite copied to clipboard

Add dev mode only tags

Open emab opened this issue 2 years ago • 6 comments

Address #62

I'm not sure if this approach is too simple - but as far as I can tell this should achieve what is needed. Doesn't add any overhead if you're not using the tags.

emab avatar Jun 05 '23 20:06 emab

Thanks for your contributions, @emab!

Just a thought: wouldn't it be cleaner to add an extra parameter (i.e. dev_only=True) to the already existing {% vite_asset %} and {% vite_asset_url %} templatetags?

thijskramer avatar Jun 06 '23 07:06 thijskramer

Thanks for your contributions, @emab!

Just a thought: wouldn't it be cleaner to add an extra parameter (i.e. dev_only=True) to the already existing {% vite_asset %} and {% vite_asset_url %} templatetags?

That's probably not a bad approach either actually, happy to implement that way if you'd prefer?

To clarify - how would we expect vite_asset_url to be used in for dev-only scenarios? I'd assume it would be used like:

<link rel="stylesheet" href="{% vite_asset_url 'path/to/my/asset.css' dev_only=True %}" />

So I'm a bit unclear if having it return nothing is suitable - it makes much more sense for the vite_asset tag though.

emab avatar Jun 06 '23 13:06 emab

Thanks for your contributions, @emab! Just a thought: wouldn't it be cleaner to add an extra parameter (i.e. dev_only=True) to the already existing {% vite_asset %} and {% vite_asset_url %} templatetags?

That's probably not a bad approach either actually, happy to implement that way if you'd prefer?

Yes please, that would make the code a bit more DRY I think.

To clarify - how would we expect vite_asset_url to be used in for dev-only scenarios? I'd assume it would be used like:

<link rel="stylesheet" href="{% vite_asset_url 'path/to/my/asset.css' dev_only=True %}" />

So I'm a bit unclear if having it return nothing is suitable - it makes much more sense for the vite_asset tag though.

I'm not sure, since I've discovered this package I've never used vite_asset_url so I'm unaware of the added value and use cases for it...

thijskramer avatar Jun 08 '23 13:06 thijskramer

I'm not sure, since I've discovered this package I've never used vite_asset_url so I'm unaware of the added value and use cases for it...

In my setup, some of my entry points in Vite are CSS files - so I use the vite_asset_url to place them in my application, e.g as above:

<link rel="stylesheet" href="{% vite_asset_url 'path/to/my/asset.css' dev_only=True %}" />

Which seems to work pretty well! However - if vite_asset_url returned nothing in dev mode I don't think it would make sense.

I'll update this to allow dev_only kwarg on the vite_asset tag as I think it makes more sense there.

emab avatar Jun 08 '23 15:06 emab

@thijskramer I've pushed an update which I've tested locally.

emab avatar Jun 08 '23 16:06 emab

Instead of:

{% vite_asset '<path to your asset>' dev_only=True %}

Could we just do:

{% if DJANGO_VITE_DEV_MODE %}
    {% vite_asset '<path to your asset>' %}
{% endif %}

It seems like this functionality could be handled on the project-level without needing to add anything to django-vite. For comparison, it doesn't seem like similar projects like django-webpack-loader or vite-ruby have support for this.

Niicck avatar Nov 15 '23 21:11 Niicck