Skip to content
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

Handle transformed assets URL #397

Merged
merged 1 commit into from
Apr 2, 2024
Merged

Conversation

batistadasilva
Copy link
Contributor

Adding the following template tag

{% webpack_asset 'path/to/original/file' %}

Fixes #343

Depends on django-webpack/webpack-bundle-tracker#125

@@ -124,3 +124,10 @@ def get_static(asset_name, config='DEFAULT'):
public_path = getattr(settings, 'STATIC_URL')

return '{0}{1}'.format(public_path, asset_name)

def get_asset(asset_name, config='DEFAULT'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a docstring similar to the one from get_static, but clarify why this is different.

asset = next((x for x in assets if x.get("sourceFilename") == name), None)
if not asset:
asset = next((x for x in assets if x["name"] == name), None)
return asset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should read like this:

    def get_asset_by_source_filename(self, name):
        files = self.get_assets()["assets"]
        return next((x for x in files if x.get("sourceFilename") == name), None)

Copy link
Member

@fjsj fjsj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, but please check suggestions. Thanks for the contribution!

@batistadasilva
Copy link
Contributor Author

@fjsj Thanks for the review!

Let me know if all changes fit the requirements

Adding the following template tag

```
{% webpack_asset 'path/to/original/file' %}
```

Fixes django-webpack#343

Depends on django-webpack/webpack-bundle-tracker#125
Copy link
Member

@fjsj fjsj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks great.

"license": "MIT",
"devDependencies": {
"webpack": "^5.91.0",
"webpack-bundle-tracker": "github:hostnfly/webpack-bundle-tracker#assets-source-filenames",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change that after merge.

@fjsj fjsj merged commit bf59f53 into django-webpack:master Apr 2, 2024
15 checks passed
@fjsj
Copy link
Member

fjsj commented Apr 4, 2024

Released at 3.1.0, thanks again @batistadasilva
If you have time, could you make a PR to update the README explaining how to use webpack_asset?
You can update this section to be mostly about webpack_asset: https://github.com/django-webpack/django-webpack-loader?tab=readme-ov-file#accessing-other-webpack-assets
And only mention webpack_static briefly, as I think the use case for webpack_asset is much more common.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not loading image processed by webpack correctly
2 participants