Skip to content

Unable to use Babel Filter with Jinja Extension #489

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

Closed
deckar01 opened this issue May 19, 2017 · 2 comments
Closed

Unable to use Babel Filter with Jinja Extension #489

deckar01 opened this issue May 19, 2017 · 2 comments

Comments

@deckar01
Copy link

I setup the Jinja extension and it works great. When I add "babel" to the filters argument, babel does not appear to be processing the assets. I believe Babel requires a preset to be provided otherwise it passes the code through untouched.

I do not see a way to provide the es2015 preset to babel using the Jinja asset tag.

{% assets filters='babel', output=output, filepath %}
  <script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}

The docs for the babel filter only show it being used with the bundle interface:

Example python bundle:

es2015 = get_filter('babel', presets='es2015')
bundle = Bundle('**/*.js', filters=es2015)

builtin_filters.html#webassets.filter.babel.Babel

@deckar01
Copy link
Author

deckar01 commented May 19, 2017

I also tried setting the OS environment variable for BABEL_PRESETS to es2015, but it did not seem to make a difference.

@deckar01
Copy link
Author

Ok, I was able to get this working. The underlying issue was that the babel presets don't invalidate the cache... I though I had cleared the cache by wiping the .webassets-cache directory, but apparently I had to wipe my output directory also.

For future reference, the cleanest way to configure filters is using the asset config:

assets_environment = AssetsEnvironment(...)
assets_environment.config['BABEL_PRESETS'] = 'es2015'

@miracle2k I didn't find this info until I read the options section of Creating custom filters. Would you be interested in reviewing a PR that adds this to the Using the tag section of the Jinja2 docs? Is there any other place in the docs that you think this information would be useful?

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

No branches or pull requests

1 participant