diff --git a/README-zh_CN.md b/README-zh_CN.md index c9ac763..8a46f10 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -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 | 考虑构建文件为最近的时间阈值(秒)| diff --git a/README.md b/README.md index 8c0b209..97cca68 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/dash_vite_plugin/plugin.py b/dash_vite_plugin/plugin.py index 4a26ee6..9d91fea 100644 --- a/dash_vite_plugin/plugin.py +++ b/dash_vite_plugin/plugin.py @@ -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: @@ -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 """ @@ -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( @@ -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): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 0641ea0..84aed6f 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -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.""" @@ -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, ) @@ -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 @@ -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']