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

Suggestion: Do not require `-legacy` suffix when using `vite_legacy_asset`

Open mixxorz opened this issue 3 years ago • 1 comments

When using vite_asset, the syntax is:

{% vite_asset 'javascript/main.js' %}

where javascript/main.js is the path to the source file.

However, when using vite_legacy_asset, the syntax requires you to add the -legacy suffix manually.

{% vite_legacy_asset 'javascript/main-legacy.js' %}

I think this might be confusing because javascript/main-legacy.js is not a file that exists. When I use vite_legacy_asset, I expect django-vite to load the legacy version of the file I specify.

{% vite_asset 'javascript/main.js' %} {# Normal version #}
{% vite_legacy_asset 'javascript/main.js' %} {# Legacy version #}

Another thing to consider is that vite_legacy_asset does not crash or give any warning when you don't add the -legacy suffix. Currently, this just loads the non-legacy version of the asset with <script nomodule>.

{% vite_legacy_asset 'javascript/main.js' %}

I think many people will be caught out by this. I suggest that django-vite not require the -legacy suffix when using vite_asset_legacy.

Keen to hear your thoughts on this.

mixxorz avatar Oct 30 '21 11:10 mixxorz

I agree with you but if some day the Vite Legacy plugin change its behaviour and put another suffix. People using Django Vite will be stuck because -legacy is hardcoded.

You're right that vite_legacy_asset do nothing more than vite_asset. But I prefer a library where people understand what they are doing, how the library works and a library where people have a maximum of control on what the library do for them.

What do you think ?

MrBin99 avatar Nov 17 '21 20:11 MrBin99