-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dev mode only tags #83
base: master
Are you sure you want to change the base?
Conversation
Thanks for your contributions, @emab! Just a thought: wouldn't it be cleaner to add an extra parameter (i.e. |
@register.simple_tag | ||
@mark_safe | ||
def vite_dev_asset_url( | ||
path: str, | ||
) -> str: | ||
""" | ||
Generates only the URL of an asset managed by ViteJS if | ||
DJANGO_VITE_DEV_MODE is True. | ||
Warning, this function does not generate URLs for dependant assets. | ||
|
||
Arguments: | ||
path {str} -- Path to a Vite asset. | ||
|
||
Raises: | ||
RuntimeError: If cannot find the asset path in the | ||
manifest (only in production). | ||
|
||
Returns: | ||
str -- The URL of this asset. | ||
""" | ||
assert path is not None | ||
|
||
if not DJANGO_VITE_DEV_MODE: | ||
return "" | ||
|
||
return DjangoViteAssetLoader.instance().generate_vite_asset_url(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly sure if this one brings any value - how would it be used? 🤔
That's probably not a bad approach either actually, happy to implement that way if you'd prefer? To clarify - how would we expect <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 |
Yes please, that would make the code a bit more DRY I think.
I'm not sure, since I've discovered this package I've never used |
In my setup, some of my entry points in Vite are CSS files - so I use the
Which seems to work pretty well! However - if I'll update this to allow |
@thijskramer I've pushed an update which I've tested locally. |
Instead of:
Could we just do:
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. |
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.