dash-vite-plugin 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dash_vite_plugin-0.1.0/PKG-INFO +427 -0
- dash_vite_plugin-0.1.0/README.md +395 -0
- dash_vite_plugin-0.1.0/dash_vite_plugin/__init__.py +7 -0
- dash_vite_plugin-0.1.0/dash_vite_plugin/plugin.py +255 -0
- dash_vite_plugin-0.1.0/dash_vite_plugin/utils.py +467 -0
- dash_vite_plugin-0.1.0/dash_vite_plugin.egg-info/PKG-INFO +427 -0
- dash_vite_plugin-0.1.0/dash_vite_plugin.egg-info/SOURCES.txt +13 -0
- dash_vite_plugin-0.1.0/dash_vite_plugin.egg-info/dependency_links.txt +1 -0
- dash_vite_plugin-0.1.0/dash_vite_plugin.egg-info/requires.txt +8 -0
- dash_vite_plugin-0.1.0/dash_vite_plugin.egg-info/top_level.txt +1 -0
- dash_vite_plugin-0.1.0/pyproject.toml +42 -0
- dash_vite_plugin-0.1.0/setup.cfg +4 -0
- dash_vite_plugin-0.1.0/tests/test_dash_integration.py +1001 -0
- dash_vite_plugin-0.1.0/tests/test_plugin.py +1053 -0
- dash_vite_plugin-0.1.0/tests/test_utils.py +1202 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dash-vite-plugin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Dash plugin for integrating Vite using Dash 3.x hooks
|
|
5
|
+
Author-email: insistence <3055204202@qq.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/HogaStack/dash-vite-plugin
|
|
7
|
+
Project-URL: Documentation, https://github.com/HogaStack/dash-vite-plugin
|
|
8
|
+
Project-URL: Repository, https://github.com/HogaStack/dash-vite-plugin
|
|
9
|
+
Project-URL: Issues, https://github.com/HogaStack/dash-vite-plugin/issues
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Framework :: Dash
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: dash>=3.0.3
|
|
26
|
+
Requires-Dist: py-node-manager>=0.1.1
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
31
|
+
Requires-Dist: twine; extra == "dev"
|
|
32
|
+
|
|
33
|
+
# Dash Vite Plugin
|
|
34
|
+
|
|
35
|
+
A Dash plugin for integrating Vite using Dash 3.x hooks, allowing you to use modern frontend build tools with your Dash applications.
|
|
36
|
+
|
|
37
|
+
[](https://github.com/HogaStack/dash-vite-plugin/actions)
|
|
38
|
+
[](https://codecov.io/gh/HogaStack/dash-vite-plugin)
|
|
39
|
+
[](https://pypi.org/project/dash-vite-plugin/)
|
|
40
|
+
[](https://pypi.org/project/dash-vite-plugin/)
|
|
41
|
+
[](https://github.com/astral-sh/ruff)
|
|
42
|
+
[](https://github.com/HogaStack/dash-vite-plugin/blob/main/LICENSE)
|
|
43
|
+
|
|
44
|
+
English | [简体中文](./README-zh_CN.md)
|
|
45
|
+
|
|
46
|
+
## Table of Contents
|
|
47
|
+
|
|
48
|
+
- [Introduction](#introduction)
|
|
49
|
+
- [Features](#features)
|
|
50
|
+
- [Installation](#installation)
|
|
51
|
+
- [Quick Start](#quick-start)
|
|
52
|
+
- [Usage Example](#usage-example)
|
|
53
|
+
- [API Reference](#api-reference)
|
|
54
|
+
- [VitePlugin Class](#viteplugin-class)
|
|
55
|
+
- [NpmPackage Class](#npmpackage-class)
|
|
56
|
+
- [Configuration Options](#configuration-options)
|
|
57
|
+
- [How It Works](#how-it-works)
|
|
58
|
+
- [Development Guide](#development-guide)
|
|
59
|
+
- [Testing](#testing)
|
|
60
|
+
- [License](#license)
|
|
61
|
+
|
|
62
|
+
## Introduction
|
|
63
|
+
|
|
64
|
+
Dash Vite Plugin is a plugin designed for the [Plotly Dash](https://plotly.com/dash/) framework that allows you to use the [Vite](https://vitejs.dev/) build tool in your Dash applications. The plugin leverages Dash 3.x's new hooks system to easily integrate modern frontend development tools into your Dash applications.
|
|
65
|
+
|
|
66
|
+
With this plugin, you can:
|
|
67
|
+
|
|
68
|
+
- Use Vue.js, React, or other frontend frameworks that support Vite
|
|
69
|
+
- Build optimized production versions
|
|
70
|
+
- Leverage modern frontend tooling with minimal configuration
|
|
71
|
+
- Integrate seamlessly with existing Dash applications
|
|
72
|
+
- Automatically build and integrate frontend assets with zero manual intervention
|
|
73
|
+
|
|
74
|
+
## Features
|
|
75
|
+
|
|
76
|
+
- ✅ Fully compatible with Dash 3.x
|
|
77
|
+
- ✅ Supports Vue.js and React
|
|
78
|
+
- ✅ Automated Node.js environment management
|
|
79
|
+
- ✅ Support for Less and Sass preprocessors
|
|
80
|
+
- ✅ Configurable build options
|
|
81
|
+
- ✅ Clean up build artifacts feature
|
|
82
|
+
- ✅ Intelligent skipping of recently built files for performance improvement
|
|
83
|
+
- ✅ Easy-to-use API
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install dash-vite-plugin
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Note: This plugin requires Python 3.8 or higher.
|
|
92
|
+
|
|
93
|
+
## Quick Start
|
|
94
|
+
|
|
95
|
+
1. Install the plugin:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pip install dash-vite-plugin
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
2. Prepare your frontend assets:
|
|
102
|
+
|
|
103
|
+
```console
|
|
104
|
+
assets/
|
|
105
|
+
├── js/
|
|
106
|
+
│ └── main.js
|
|
107
|
+
└── vue/
|
|
108
|
+
└── App.vue
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
3. Use the plugin in your Dash application:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from dash import Dash
|
|
115
|
+
from dash_vite_plugin import VitePlugin
|
|
116
|
+
|
|
117
|
+
# Create plugin instance
|
|
118
|
+
vite_plugin = VitePlugin(
|
|
119
|
+
build_assets_paths=['assets/js', 'assets/vue'],
|
|
120
|
+
entry_js_paths=['assets/js/main.js'],
|
|
121
|
+
npm_packages=[]
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# Call setup() before creating Dash app
|
|
125
|
+
vite_plugin.setup()
|
|
126
|
+
|
|
127
|
+
# Create Dash app
|
|
128
|
+
app = Dash(__name__)
|
|
129
|
+
|
|
130
|
+
# Call use() after creating Dash app
|
|
131
|
+
vite_plugin.use(app)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Usage Example
|
|
135
|
+
|
|
136
|
+
For detailed usage examples, please refer to the example files:
|
|
137
|
+
|
|
138
|
+
- [Vue.js Example](example_vue.py) - Demonstrates how to use the plugin with Vue.js
|
|
139
|
+
- [React Example](example_react.py) - Demonstrates how to use the plugin with React
|
|
140
|
+
|
|
141
|
+
These examples show how to set up the plugin with different frontend frameworks and include test callbacks to verify that the integration is working correctly.
|
|
142
|
+
|
|
143
|
+
## API Reference
|
|
144
|
+
|
|
145
|
+
### VitePlugin Class
|
|
146
|
+
|
|
147
|
+
VitePlugin is the main plugin class responsible for managing the Vite build process.
|
|
148
|
+
|
|
149
|
+
#### VitePlugin Constructor Parameters
|
|
150
|
+
|
|
151
|
+
| Parameter | Type | Default | Description |
|
|
152
|
+
|-----------|------|---------|-------------|
|
|
153
|
+
| build_assets_paths | List[str] | Required | List of asset paths to build |
|
|
154
|
+
| entry_js_paths | List[str] | Required | List of entry JavaScript file paths |
|
|
155
|
+
| npm_packages | List[NpmPackage] | Required | List of npm packages |
|
|
156
|
+
| plugin_tmp_dir | str | '_vite' | Plugin temporary directory |
|
|
157
|
+
| support_less | bool | False | Whether to support Less |
|
|
158
|
+
| support_sass | bool | False | Whether to support Sass |
|
|
159
|
+
| download_node | bool | False | Whether to download Node.js if not found |
|
|
160
|
+
| node_version | str | '18.17.0' | Node.js version to download |
|
|
161
|
+
| clean_after | bool | False | Whether to clean up generated files after build |
|
|
162
|
+
| skip_build_if_recent | bool | True | Whether to skip build if built file was recently generated |
|
|
163
|
+
| skip_build_time_threshold | int | 5 | Time threshold in seconds to consider built file as recent |
|
|
164
|
+
|
|
165
|
+
#### VitePlugin Methods
|
|
166
|
+
|
|
167
|
+
##### setup()
|
|
168
|
+
|
|
169
|
+
Set up the Vite plugin, called before creating the Dash app.
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
vite_plugin.setup()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
##### use(app)
|
|
176
|
+
|
|
177
|
+
Use the plugin with a Dash app, called after creating the Dash app.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
vite_plugin.use(app)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Parameters:
|
|
184
|
+
|
|
185
|
+
- app (Dash): The Dash app instance to use
|
|
186
|
+
|
|
187
|
+
### NpmPackage Class
|
|
188
|
+
|
|
189
|
+
NpmPackage is used to define npm packages to install.
|
|
190
|
+
|
|
191
|
+
#### NpmPackage Constructor Parameters
|
|
192
|
+
|
|
193
|
+
| Parameter | Type | Default | Description |
|
|
194
|
+
|-----------|------|---------|-------------|
|
|
195
|
+
| name | str | Required | npm package name |
|
|
196
|
+
| version | str | 'latest' | npm package version |
|
|
197
|
+
| install_mode | Literal['-D', '-S'] | '-S' | Installation mode (-D for dev dependency, -S for prod dependency) |
|
|
198
|
+
|
|
199
|
+
#### NpmPackage Usage Example
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from dash_vite_plugin import NpmPackage
|
|
203
|
+
|
|
204
|
+
npm_packages = [
|
|
205
|
+
NpmPackage('vue'), # Use latest version
|
|
206
|
+
NpmPackage('react', '18.2.0'), # Specify version
|
|
207
|
+
NpmPackage('sass', install_mode='-D'), # Install as dev dependency
|
|
208
|
+
]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Configuration Options
|
|
212
|
+
|
|
213
|
+
### Plugin Temporary Directory
|
|
214
|
+
|
|
215
|
+
The plugin creates a temporary directory during the build process to store build files. The default is `_vite`. You can customize it with the `plugin_tmp_dir` parameter:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
vite_plugin = VitePlugin(
|
|
219
|
+
# ... other parameters
|
|
220
|
+
plugin_tmp_dir='my_custom_dir'
|
|
221
|
+
)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Less and Sass Support
|
|
225
|
+
|
|
226
|
+
To enable Less or Sass support, simply set the corresponding parameters to `True`:
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
vite_plugin = VitePlugin(
|
|
230
|
+
# ... other parameters
|
|
231
|
+
support_less=True, # Enable Less support
|
|
232
|
+
support_sass=True, # Enable Sass support
|
|
233
|
+
)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Node.js Management
|
|
237
|
+
|
|
238
|
+
The plugin uses [py-node-manager](https://github.com/HogaStack/py-node-manager) to manage the Node.js environment:
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
vite_plugin = VitePlugin(
|
|
242
|
+
# ... other parameters
|
|
243
|
+
download_node=True, # Download Node.js if not found
|
|
244
|
+
node_version='18.17.0' # Specify Node.js version to download
|
|
245
|
+
)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Cleanup Options
|
|
249
|
+
|
|
250
|
+
After building, you can choose to clean up generated files to keep the directory tidy:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
vite_plugin = VitePlugin(
|
|
254
|
+
# ... other parameters
|
|
255
|
+
clean_after=True # Clean up files after build
|
|
256
|
+
)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Build Skip Optimization
|
|
260
|
+
|
|
261
|
+
To avoid unnecessary repeated builds, the plugin can skip recently built files:
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
vite_plugin = VitePlugin(
|
|
265
|
+
# ... other parameters
|
|
266
|
+
skip_build_if_recent=True, # Enable build skipping
|
|
267
|
+
skip_build_time_threshold=10 # Set time threshold to 10 seconds
|
|
268
|
+
)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## How It Works
|
|
272
|
+
|
|
273
|
+
1. **Initialization Phase**:
|
|
274
|
+
- Plugin creates necessary config files (vite.config.js, index.html, package.json)
|
|
275
|
+
- Copies specified asset files to temporary directory
|
|
276
|
+
|
|
277
|
+
2. **Installation Phase**:
|
|
278
|
+
- Initializes npm environment
|
|
279
|
+
- Installs Vite and related plugins
|
|
280
|
+
- Installs specified npm packages
|
|
281
|
+
- Installs Less or Sass support based on configuration
|
|
282
|
+
|
|
283
|
+
3. **Build Phase**:
|
|
284
|
+
- Uses Vite to build assets
|
|
285
|
+
- Generates optimized static files
|
|
286
|
+
|
|
287
|
+
4. **Integration Phase**:
|
|
288
|
+
- Extracts built script and style tags
|
|
289
|
+
- Injects them into Dash app's HTML
|
|
290
|
+
- Sets up static file serving routes
|
|
291
|
+
|
|
292
|
+
5. **Cleanup Phase** (optional):
|
|
293
|
+
- Deletes temporary files and directories to keep environment tidy
|
|
294
|
+
|
|
295
|
+
## Development Guide
|
|
296
|
+
|
|
297
|
+
### Project Structure
|
|
298
|
+
|
|
299
|
+
```console
|
|
300
|
+
dash-vite-plugin/
|
|
301
|
+
├── dash_vite_plugin/ # Plugin source code
|
|
302
|
+
│ ├── __init__.py # Package initialization file
|
|
303
|
+
│ ├── plugin.py # Main plugin class implementation
|
|
304
|
+
│ └── utils.py # Utility functions and helper classes
|
|
305
|
+
├── tests/ # Test files
|
|
306
|
+
│ ├── conftest.py # Pytest configuration and fixtures
|
|
307
|
+
│ ├── test_plugin.py # Tests for VitePlugin class functionality
|
|
308
|
+
│ ├── test_utils.py # Tests for utility functions and ViteCommand class
|
|
309
|
+
│ └── test_dash_integration.py # Integration tests with Dash application
|
|
310
|
+
├── example_vue.py # Complete usage example demonstrating the plugin with Vue.js
|
|
311
|
+
├── example_react.py # Complete usage example demonstrating the plugin with React
|
|
312
|
+
├── pyproject.toml # Project configuration and metadata
|
|
313
|
+
├── requirements-dev.txt # Development dependencies
|
|
314
|
+
└── ruff.toml # Ruff linting configuration
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Development Environment Setup
|
|
318
|
+
|
|
319
|
+
1. Clone the repository:
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
git clone https://github.com/HogaStack/dash-vite-plugin.git
|
|
323
|
+
cd dash-vite-plugin
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
2. Install development dependencies:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
pip install -r requirements-dev.txt
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
3. Install the project:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
pip install -e .
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Code Quality
|
|
339
|
+
|
|
340
|
+
This project uses [Ruff](https://github.com/astral-sh/ruff) for linting and code formatting. The configuration is in [ruff.toml](ruff.toml).
|
|
341
|
+
|
|
342
|
+
To check for linting issues:
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
ruff check .
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
To automatically fix linting issues:
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
ruff check . --fix
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
To check if the code conforms to the formatting standards without making changes:
|
|
355
|
+
|
|
356
|
+
```bash
|
|
357
|
+
ruff format . --check
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
To format the code according to the project's style guide:
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
ruff format .
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Running the Example
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
# Run the Vue.js example
|
|
370
|
+
python example_vue.py
|
|
371
|
+
|
|
372
|
+
# Run the React example
|
|
373
|
+
python example_react.py
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## Testing
|
|
377
|
+
|
|
378
|
+
This project includes a comprehensive test suite covering unit tests and integration tests.
|
|
379
|
+
|
|
380
|
+
### Test Structure
|
|
381
|
+
|
|
382
|
+
- `conftest.py`: Contains pytest configuration and fixtures
|
|
383
|
+
- `test_plugin.py`: Tests main functionality of VitePlugin class
|
|
384
|
+
- `test_utils.py`: Tests utility functions and ViteCommand class
|
|
385
|
+
- `test_dash_integration.py`: Integration tests for VitePlugin with Dash app integration
|
|
386
|
+
|
|
387
|
+
### Running Tests
|
|
388
|
+
|
|
389
|
+
```bash
|
|
390
|
+
# Run all tests
|
|
391
|
+
python -m pytest tests/ -v
|
|
392
|
+
|
|
393
|
+
# Run specific test file
|
|
394
|
+
python -m pytest tests/test_plugin.py -v
|
|
395
|
+
|
|
396
|
+
# Run integration tests
|
|
397
|
+
python -m pytest tests/test_dash_integration.py -v
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Test Dependencies
|
|
401
|
+
|
|
402
|
+
Make sure you have installed the test dependencies:
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
pip install -r requirements-dev.txt
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
This will install:
|
|
409
|
+
|
|
410
|
+
- py-node-manager: For managing Node.js environment
|
|
411
|
+
- pytest: Testing framework
|
|
412
|
+
- pytest-cov: Coverage reporting for tests
|
|
413
|
+
- dash[testing]: Dash framework testing dependencies
|
|
414
|
+
|
|
415
|
+
### Test Coverage
|
|
416
|
+
|
|
417
|
+
Tests cover the following functionalities:
|
|
418
|
+
|
|
419
|
+
1. Initialization and configuration of VitePlugin class
|
|
420
|
+
2. Functionality of utility functions and ViteCommand class
|
|
421
|
+
3. File copying and asset handling
|
|
422
|
+
4. Integration tests with different configuration options
|
|
423
|
+
5. Mock tests to avoid actual Node.js calls
|
|
424
|
+
|
|
425
|
+
## License
|
|
426
|
+
|
|
427
|
+
See [LICENSE](LICENSE) file for details.
|