Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Plugin to simplify use of Vite from Flask.
Instantiate the Flask extension as you do for other Flask extensions:
from flask_vite import Vite
app = Flask(...)
vite = Vite(app)
# or
vite = Vite()
vite.init_app(app)
Then you can use the following commands:
$ flask vite
Usage: flask vite [OPTIONS] COMMAND [ARGS]...
Perform Vite operations.
Options:
--help Show this message and exit.
Commands:
build Build the Vite assets.
check-updates Check outdated Vite dependencies.
init Init the vite/ directory (if it doesn't exist)
install Install the dependencies using npm.
start Start watching source changes for dev.
update Update Vite and its dependencies, if needed.
This section assumes you have already added Flask-Vite to your Flask app with the steps above.
# First, create the /vite subdirectory in your Flask app's root folder
$ flask vite init
# Install any dependencies
$ flask vite install
# Start a local Vite dev server.
# This will hot-reload any changes in the /vite subdirectory, so it's suited for local development.
$ flask vite start
# Make any changes in vite/main.js, such as importing React/Vue components.
# Flask-Vite assumes you have a single entry point at vite/main.js, such as a React SPA (single page application).
You should now be able to see any changes you have made in your Flask app. If not, try Troubleshooting.
Once you are ready for production, you need to build your assets.
# Build assets based on /vite/vite.config.js
$ flask vite build
You should now see files like /vite/dist/assets/index-f16ca036.js
.
If you are running your Flask app in production mode (ie without app.debug), you should see these asset files included in your Flask Jinja templates automatically. If not, try Troubleshooting.
vite
directory where you put your front-end source code.VITE_AUTO_INSERT
is set in the Flask config).{{ vite_tags() }}
in your Jinja templates otherwise.host_matching
mode, you can tell Vite which host to mount its own views on. You can configure this when instantiating Vite or when calling init_app
:
vite_routes_host
the specific single host to serve its assets from.vite_routes_host
as the wildcard value *
to serve vite assets from the same domain as the current request.The following (Flask) configuration variables are available:
VITE_AUTO_INSERT
: if set, the extension will auto-insert the Vite assets into your HTML pages.VITE_NPM_BIN_PATH
: path to the npm
binary. Defaults to npm
.VITE_FOLDER_PATH
: path for the vite project. Defaults to vite
locally.See the demo/
directory for a working demo using TailwindCSS.
VITE_AUTO_INSERT=True
in your Flask config{{ vite_tags() }}
somewhere in your Jinja templatesEither of these options will insert <script> tags into your Jinja templates, which will be the output of your vite config.
<script type="module" src="http://localhost:3000/main.js"></script>
flask vite start
<script type="module" src="/_vite/index-f16ca036.js"></script>
(the hash in index-[hash].js
will change every time)/vite/dist/assets/index-f16ca036.js
. If not, you can build for production again using flask vite build
This project is inspired by the
Django-Tailwind project and was previously known as Flask-Tailwind
.
This package was created with Cookiecutter, using the abilian/cookiecutter-abilian-python project template.
FAQs
Flask+Vite integration.
We found that flask-vite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.