Flask extension for connecting and managing webpack assets
Project description
What is Flask-Manage-Webpack?
A Flask extension that connect and manage your webpack generated assets.
Flask-Manage-Webpack
reads a manifest.json file auto-generated by webpack-manifest-plugin
,
and out of the box it made possible to:
- Import your assets via
webpack_url_for()
in your templates. - Browser caching via hash tagging.
- Code splitting and dynamic import().
- Compatible with Content-Security-Policy:
e.g. script-src: 'nonce-<random-value>
- Working with CDN, and static host provider such as
Netlify
for making your Webpack build process automated. - Extending the functionality by using Webpack.
Quick start
Install: pip install Flask-Manage-Webpack
from flask import Flask
from flask_manage_webpack import FlaskManageWebpack
app = Flask(__name__.split(".")[0])
# Register Extension
manage_webpack = FlaskManageWebpack()
manage_webpack.init_app(app)
Initialize Webpack Config:
- Run
flask manage-webpack --app your_flask_app
- It will generate config files for webpack.
Run Webpack: npm start
For more info, checkout the demo app inside example folder.
How to import assets in HTML?
Import your main stylesheet to HTML:
<link rel="stylesheet" href="{{ webpack_url_for('main_css.css') }}">
Import your main JavaScript to HTML:
<script id="main_js" src="{{ webpack_url_for('main_js.js') }}"></script>
What about images, and other files?
- Put your images to
assets/img/
or to your preferred folder structure. - In HTML, import your image via relative path:
<img src="{{ webpack_url_for('img/something.jpg') }}">
Config Variables:
MANAGE_WEBPACK_MANIFEST_PATH
defaults tostatic/manifest.json
MANAGE_WEBPACK_ASSETS_URL
: Your static url domain name. Defaults toNone
MANAGE_WEBPACK_MANIFEST_URL
: Your absolute manifest.json url. This is useful if you wish to host you manifest.json file in a remote server, and if you like to automate your Webpack build process by hosting it to such service likeNetlify
. i.e.https://example.com/manifest.json
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Flask-Manage-Webpack-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3894426dccf89a3e4d04add246200310852edd2c5c07432a425cfe302426e8b9 |
|
MD5 | 961424f6029ea50c4bf8f21a679019ba |
|
BLAKE2b-256 | c9ab725879a3931b1dd64a0d0fabe169b3d2ee5b017a355ab675ccbb291e9da9 |
Hashes for Flask_Manage_Webpack-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d751e38edfb84ec3f3d6316996a1c4abef013d0897c4f906c5eb5dd1cd545787 |
|
MD5 | 7af91c422c085d061c6787b2dc201727 |
|
BLAKE2b-256 | dbebf5875abe659d3cd0053968780fda257a1d53a2621e02a6690f7db0b46397 |