Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ VitePlugin 是负责管理 Vite 构建过程的主要插件类。
| download_node | bool | False | 如果未找到是否下载 Node.js |
| node_version | str | '18.17.0' | 要下载的 Node.js 版本 |
| clean_after | bool | False | 构建后是否清理生成的文件 |
| skip_build | bool | False | 是否跳过构建执行 |
| skip_build_if_recent | bool | True | 如果构建文件是最近生成的是否跳过构建 |
| skip_build_time_threshold | int | 5 | 考虑构建文件为最近的时间阈值(秒)|

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ VitePlugin is the main plugin class responsible for managing the Vite build proc
| download_node | bool | False | Whether to download Node.js if not found |
| node_version | str | '18.17.0' | Node.js version to download |
| clean_after | bool | False | Whether to clean up generated files after build |
| skip_build | bool | False | Whether to skip build execution |
| skip_build_if_recent | bool | True | Whether to skip build if built file was recently generated |
| skip_build_time_threshold | int | 5 | Time threshold in seconds to consider built file as recent |

Expand Down
5 changes: 5 additions & 0 deletions dash_vite_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
download_node: bool = False,
node_version: str = '18.20.8',
clean_after: bool = False,
skip_build: bool = False,
skip_build_if_recent: bool = True,
skip_build_time_threshold: int = 5,
) -> None:
Expand All @@ -45,6 +46,7 @@ def __init__(
download_node (bool): Whether to download Node.js if not found
node_version (str): Node.js version to download if download_node is True
clean_after (bool): Whether to clean up generated files after build
skip_build (bool): Whether to skip build execution
skip_build_if_recent (bool): Whether to skip build if built file was recently generated
skip_build_time_threshold (int): Time threshold in seconds to consider built file as recent
"""
Expand All @@ -57,6 +59,7 @@ def __init__(
self.download_node = download_node
self.node_version = node_version
self.clean_after = clean_after
self.skip_build = skip_build
self.skip_build_if_recent = skip_build_if_recent
self.skip_build_time_threshold = skip_build_time_threshold
self.vite_command = ViteCommand(
Expand Down Expand Up @@ -194,6 +197,8 @@ def _should_skip_build(self) -> bool:
Returns:
bool: True if the build should be skipped, False otherwise
"""
if self.skip_build:
return True
# Check if CSS file exists and was generated recently (within threshold seconds)
check_index_path = os.path.join(self.plugin_tmp_dir, 'dist', 'index.html')
if self.skip_build_if_recent and os.path.exists(check_index_path):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_plugin_initialization(self):
assert plugin.clean_after is False
assert plugin.skip_build_if_recent is True
assert plugin.skip_build_time_threshold == 5
assert plugin.skip_build is False

def test_plugin_initialization_with_custom_parameters(self):
"""Test plugin initialization with custom parameters."""
Expand All @@ -59,6 +60,7 @@ def test_plugin_initialization_with_custom_parameters(self):
download_node=True,
node_version='20.0.0',
clean_after=True,
skip_build=True,
skip_build_if_recent=False,
skip_build_time_threshold=10,
)
Expand All @@ -72,6 +74,7 @@ def test_plugin_initialization_with_custom_parameters(self):
assert plugin.download_node is True
assert plugin.node_version == '20.0.0'
assert plugin.clean_after is True
assert plugin.skip_build is True
assert plugin.skip_build_if_recent is False
assert plugin.skip_build_time_threshold == 10

Expand Down Expand Up @@ -399,6 +402,25 @@ def test_extract_assets_tags_no_file(self):
# Should return empty string
assert tags == ''

def test_skip_build_param(self):
"""Test the skip build logic when skip_build param is True."""
build_assets_paths = ['assets/js']
entry_js_paths = ['assets/js/main.js']
npm_packages = [NpmPackage('react')]

plugin = VitePlugin(
build_assets_paths=build_assets_paths,
entry_js_paths=entry_js_paths,
npm_packages=npm_packages,
skip_build=True,
)

# Check the skip logic directly
should_skip = plugin._should_skip_build()

# Should be True
assert should_skip is True

def test_skip_build_logic_recent_file(self):
"""Test the skip build logic when file is recent."""
build_assets_paths = ['assets/js']
Expand Down
Loading