Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check unreadable manifest to enable dev mode [CakePHP 4] #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/app_vite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/Utilities/ConfigDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 9 additions & 0 deletions src/View/Helper/ViteScriptsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Loading