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 8139a01 commit 06c8385
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 $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 $includeScriptOnloadHandler = true;

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

Expand Down Expand Up @@ -542,6 +547,9 @@ protected function manifestRegisterTags(array $tags, array $legacyTags)
$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 @@ -623,6 +631,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 06c8385

Please sign in to comment.