diff --git a/README.md b/README.md index a02c909..02d4b08 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ your own instance of `ViteHelperConfig` to a helper method as a second parameter 'styleEntries' => ['someFolder/myStyleEntry.scss'], // relative to project root. Unnecessary when using css-in-js. 'hostNeedles' => ['.test', '.local'], // to check if the app is running locally 'url' => 'http://localhost:3000', // url of the vite dev server + 'checkManifest' => false, // check if the manifest file does not exist and enable dev mode ], 'forceProductionMode' => false, // or true to always serve build assets 'plugin' => false, // or string 'MyPlugin' to serve plugin build assets diff --git a/config/app_vite.php b/config/app_vite.php index 5312d69..a4ad044 100644 --- a/config/app_vite.php +++ b/config/app_vite.php @@ -12,6 +12,7 @@ 'scriptEntries' => ConfigDefaults::DEVELOPMENT_SCRIPT_ENTRIES, 'styleEntries' => ConfigDefaults::DEVELOPMENT_STYLE_ENTRIES, 'hostNeedles' => ConfigDefaults::DEVELOPMENT_HOST_NEEDLES, + 'checkManifest' => ConfigDefaults::DEVELOPMENT_CHECK_MANIFEST, 'url' => ConfigDefaults::DEVELOPMENT_URL, ], 'forceProductionMode' => ConfigDefaults::FORCE_PRODUCTION_MODE, diff --git a/src/Utilities/ConfigDefaults.php b/src/Utilities/ConfigDefaults.php index 28b7328..e33075d 100644 --- a/src/Utilities/ConfigDefaults.php +++ b/src/Utilities/ConfigDefaults.php @@ -25,6 +25,11 @@ class ConfigDefaults '127.0.0.1', ]; + /** + * If true, the manifest file will be checked for existence and readability in order to detect development mode + */ + public const DEVELOPMENT_CHECK_MANIFEST = false; + /** * for Cookies or URL-params to force production mode */ diff --git a/src/View/Helper/ViteScriptsHelper.php b/src/View/Helper/ViteScriptsHelper.php index 3d54a7d..a39bb0f 100644 --- a/src/View/Helper/ViteScriptsHelper.php +++ b/src/View/Helper/ViteScriptsHelper.php @@ -8,6 +8,7 @@ use Cake\View\Helper; use ViteHelper\Exception\ConfigurationException; use ViteHelper\Exception\InvalidArgumentException; +use ViteHelper\Exception\ManifestNotFoundException; use ViteHelper\Utilities\ConfigDefaults; use ViteHelper\Utilities\ManifestRecord; use ViteHelper\Utilities\ManifestRecords; @@ -55,6 +56,14 @@ public function isDev(?ViteHelperConfig $config = null): bool } } + if ($config->read('development.checkManifest', ConfigDefaults::DEVELOPMENT_CHECK_MANIFEST)) { + try { + ViteManifest::getRecords($config); + } catch (ManifestNotFoundException $e) { + return true; + } + } + return false; }