Skip to content

Commit

Permalink
Merge pull request #148 from hansegucker/deactivate-nomodule-polyfill
Browse files Browse the repository at this point in the history
Add option to deactivate nomodule for polyfill
  • Loading branch information
MrBin99 authored Dec 30, 2024
2 parents e4f2bfb + a0f8919 commit cb725f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions django_vite/core/asset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ def generate_vite_asset_url(self, path: str) -> str:

def generate_vite_legacy_polyfills(
self,
nomodule: bool = True,
**kwargs: Dict[str, str],
) -> str:
"""
Expand Down Expand Up @@ -542,7 +543,9 @@ def generate_vite_legacy_polyfills(
f"at {self.manifest.manifest_path}"
)

scripts_attrs = {"nomodule": "", "crossorigin": "", **kwargs}
scripts_attrs = {"crossorigin": "", **kwargs}
if nomodule:
scripts_attrs["nomodule"] = ""
url = self._get_production_server_url(polyfills_manifest_entry.file)

return TagGenerator.script(
Expand Down Expand Up @@ -820,10 +823,11 @@ def generate_vite_asset_url(
def generate_vite_legacy_polyfills(
self,
app: str = DEFAULT_APP_NAME,
nomodule: bool = True,
**kwargs: Dict[str, str],
) -> str:
app_client = self._get_app_client(app)
return app_client.generate_vite_legacy_polyfills(**kwargs)
return app_client.generate_vite_legacy_polyfills(nomodule, **kwargs)

def generate_vite_legacy_asset(
self,
Expand Down
7 changes: 5 additions & 2 deletions django_vite/templatetags/django_vite.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def vite_asset_url(path: str, app: str = DEFAULT_APP_NAME) -> str:

@register.simple_tag
@mark_safe
def vite_legacy_polyfills(app: str = DEFAULT_APP_NAME, **kwargs: Dict[str, str]) -> str:
def vite_legacy_polyfills(
app: str = DEFAULT_APP_NAME, nomodule: bool = True, **kwargs: Dict[str, str]
) -> str:
"""
Generates a <script> tag to the polyfills generated
by '@vitejs/plugin-legacy' if used.
Expand All @@ -125,6 +127,7 @@ def vite_legacy_polyfills(app: str = DEFAULT_APP_NAME, **kwargs: Dict[str, str])
app {str} -- Configuration to use.
Keyword Arguments:
nomodule {bool} -- Set nomodule attribute, enabled per default.
**kwargs {Dict[str, str]} -- Adds new attributes to generated
script tags.
Expand All @@ -136,7 +139,7 @@ def vite_legacy_polyfills(app: str = DEFAULT_APP_NAME, **kwargs: Dict[str, str])
str -- The script tag to the polyfills.
"""
return DjangoViteAssetLoader.instance().generate_vite_legacy_polyfills(
app, **kwargs
app, nomodule, **kwargs
)


Expand Down

0 comments on commit cb725f4

Please sign in to comment.