English | 简体中文
Cookiecutter template for building Dash component libraries with a modern Vite-powered JavaScript build.
This template keeps the core Python/Dash workflow of Plotly's Webpack-based dash-component-boilerplate: it generates React component source, Dash Python wrappers, package metadata, tests, and publish-ready assets. The JavaScript build is implemented with Vite instead of Webpack.
- Vite 8 library builds for Dash browser bundles.
- React component templates for function and class components.
- Optional async component output with Dash-aware lazy loading.
- Python wrapper generation through Dash's component generator.
- Local Vite demo app for fast frontend iteration.
- Publish validation for generated JavaScript, CSS, metadata, and
MANIFEST.in. - Python package wrapper generation through
node scripts/generate-components.mjs.
- Python 3.8+
- Node.js
^20.19.0 || >=22.12.0 - npm 10+
cookiecutter
The generated project enforces this Node.js requirement during dependency installation and JavaScript builds.
Install Cookiecutter if needed:
pip install cookiecutterFrom a local checkout:
cookiecutter path/to/dash-component-vite-boilerplateFrom GitHub:
cookiecutter gh:HogaStack/dash-component-vite-boilerplateYou will be prompted for:
project_name: Human-readable project name, for exampleDash Core Components.project_shortname: Python package name. It must be lowercase and may contain numbers and_.component_name: Initial React component name. It should be PascalCase, for exampleMyComponent.component_type: Function component or class component.use_async: Whether to generate the initial component as an async/lazy-loaded component.author_name/author_email: Package metadata.github_org: Optional GitHub owner used for package URLs.description: Package description.license: Generated package license metadata.publish_on_npm: Whether Dash should include unpkg URLs for CDN serving.install_dependencies: Whether the post-generation hook should install dependencies and run the initial build.
The generated project is created in a folder named after project_shortname.
Inside the generated project:
npm install
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txtOn macOS/Linux, activate with:
. venv/bin/activateCommon commands:
npm start
npm run build:js
npm run build:python
npm run build
npm run lint
python usage.pynpm startruns the standalone Vite demo app fromsrc/demo.npm run build:jswrites Dash JavaScript bundles into the Python package directory.npm run build:pythonregenerates Python wrappers fromsrc/lib/components.npm run buildruns both JavaScript and Python wrapper generation.python usage.pystarts a sample Dash app using the generated component.
When use_async=True, the template generates:
- a public wrapper in
src/lib/components/<ComponentName>.react.js - a real implementation fragment in
src/lib/fragments/<ComponentName>.react.js - an
async-<ComponentName>.jsbundle duringnpm run build:js
The Vite build scans src/lib/fragments/*.react.js, so additional async fragments can be added later. Async bundles are loaded through Dash's _dash-component-suites route when serving locally. If publish_on_npm=True, CDN URLs are also registered for unpkg.
Before publishing a generated component library:
npm run build
npm run validate-init
python setup.py sdist bdist_wheelvalidate-init checks that generated assets are registered in the Dash package and included by MANIFEST.in. It exits with a non-zero status when publish-critical files are missing.
If publish_on_npm=False, Dash will serve assets locally from the Python package. If publish_on_npm=True, publish the npm package as well so unpkg URLs resolve correctly.
Install template test requirements:
pip install -r tests/requirements.txtRun the lightweight generation test:
pytest tests/test_generate.pyThe install/browser integration test requires npm, Chrome/Chromedriver, and Dash testing dependencies:
pytest tests/test_install.py --headlessVite/Rollup/Rolldown do not provide Webpack's runtime chunk behavior for IIFE builds. This template uses explicit Vite library builds plus a small Dash-aware async loader to preserve Dash async component behavior.
For comparison with the original Webpack implementation, see Plotly's dash-component-boilerplate.