Skip to content

Commit

Permalink
feat: Added an includeScriptOnloadHandler config setting that allow…
Browse files Browse the repository at this point in the history
…s you to disable the adding of an `onload` handler on the `<script>` tags (useful when implementing a Content Security Policy)
  • Loading branch information
khalwat committed Aug 13, 2024
1 parent fc16041 commit 014f076
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/services/ViteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class ViteService extends Component
*/
public bool $includeModulePreloadShim = true;

/**
* @var bool Whether an onload handler should be added to <script> tags to fire a custom event when the script has loaded
*/
public bool $includeScriptOnloadHandler = true;

// Protected Properties
// =========================================================================

Expand Down Expand Up @@ -538,6 +543,9 @@ protected function manifestRegisterTags(array $tags, array $legacyTags): void
$url = FileHelper::createUrl($this->serverPublic, $tag['url']);
switch ($tag['type']) {
case 'file':
if (!$this->includeScriptOnloadHandler) {
unset($tag['options']['onload']);
}
$view->registerJsFile(
$url,
$tag['options'],
Expand Down Expand Up @@ -619,6 +627,9 @@ protected function manifestScriptTags(array $tags, array $legacyTags): array
$url = FileHelper::createUrl($this->serverPublic, $tag['url']);
switch ($tag['type']) {
case 'file':
if (!$this->includeScriptOnloadHandler) {
unset($tag['options']['onload']);
}
$lines[] = HtmlHelper::jsFile($url, $tag['options']);
break;
case 'css':
Expand Down

0 comments on commit 014f076

Please sign in to comment.