feat: allow globs when specifynigg additionall JS and CSS (#1043)

* feat: allow globs when specifynigg additionall JS and CSS

* refactor: fix tests and linter errors
This commit is contained in:
Juro Oravec 2025-03-21 10:23:38 +01:00 committed by GitHub
parent 73e94b6714
commit ab75cfdb8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 282 additions and 97 deletions

View file

@ -143,17 +143,22 @@ However, there's a few differences from Django's Media class:
2. Individual JS / CSS files can be any of `str`, `bytes`, `Path`,
[`SafeString`](https://docs.djangoproject.com/en/5.1/ref/utils/#django.utils.safestring.SafeString), or a function
(See [`ComponentMediaInputPath`](../../../reference/api#django_components.ComponentMediaInputPath)).
3. Individual JS / CSS files can be glob patterns, e.g. `*.js` or `styles/**/*.css`.
4. If you set [`Media.extend`](../../../reference/api/#django_components.ComponentMediaInput.extend) to a list,
it should be a list of [`Component`](../../../reference/api/#django_components.Component) classes.
```py
class MyTable(Component):
class Media:
js = [
"path/to/script.js",
"path/to/*.js", # Or as a glob
"https://unpkg.com/alpinejs@3.14.7/dist/cdn.min.js", # AlpineJS
]
css = {
"all": [
"path/to/style.css",
"path/to/*.css", # Or as a glob
"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", # TailwindCSS
],
"print": ["path/to/style2.css"],