Skip to content

Instantly share code, notes, and snippets.

@sasha-id
Created July 20, 2022 05:15
Show Gist options
  • Save sasha-id/59f5e57cc9d287b98990e9789f78b9a7 to your computer and use it in GitHub Desktop.
Save sasha-id/59f5e57cc9d287b98990e9789f78b9a7 to your computer and use it in GitHub Desktop.
jinja2 webpack extension for flask/quart: add this to __init__.py
# Webpack loader: manifest.json map generated by webpacker
manifest = orjson.loads(open(f'{app.static_folder}/dist/manifest.json').read())
def webpack(pack):
filename = 'bundle.js' if app.config['ENV'] == 'development' else manifest.get(pack)
return f'{app.static_url_path}/dist/{filename}'
app.jinja_env.globals.update(webpack=webpack)
# Use in template <script src="{{ webpack('main.js') }}"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment