django-vite
django-vite copied to clipboard
Add dev mode only tags
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.
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?
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.
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_urlto 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_assettag 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...
I'm not sure, since I've discovered this package I've never used
vite_asset_urlso 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.
@thijskramer I've pushed an update which I've tested locally.
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.