Support type="module" for JS files loaded from template v2 #2482

This commit is contained in:
Kijin Sung 2025-02-15 22:04:50 +09:00
parent 4bf4aca762
commit 5b575f9c30
2 changed files with 10 additions and 4 deletions

View file

@ -72,7 +72,7 @@ class FrontEndFileHandler extends Handler
* <pre> * <pre>
* case js * case js
* $args[0]: file name * $args[0]: file name
* $args[1]: type (head | body) * $args[1]: type (head | body | module)
* $args[2]: unused (previously targetIe) * $args[2]: unused (previously targetIe)
* $args[3]: index * $args[3]: index
* case css * case css
@ -245,6 +245,7 @@ class FrontEndFileHandler extends Handler
} }
else if($file->fileExtension == 'js') else if($file->fileExtension == 'js')
{ {
$file->jstype = $media === 'module' ? $media : '';
$file->key = sprintf('%s/%s', $file->filePath, $file->keyName); $file->key = sprintf('%s/%s', $file->filePath, $file->keyName);
} }
@ -602,7 +603,12 @@ class FrontEndFileHandler extends Handler
{ {
$url .= '?t=' . filemtime($file->fileFullPath); $url .= '?t=' . filemtime($file->fileFullPath);
} }
$result[] = array('file' => $url); $attrs = '';
if ($file->jstype)
{
$attrs = ' type="' . $file->jstype . '"';
}
$result[] = array('file' => $url, 'attrs' => $attrs);
} }
} }
} }
@ -624,7 +630,7 @@ class FrontEndFileHandler extends Handler
{ {
foreach ($indexedMap as $file) foreach ($indexedMap as $file)
{ {
if ($file->isExternalURL || !is_readable($file->fileFullPath)) if ($file->isExternalURL || !is_readable($file->fileFullPath) || !empty($file->jstype))
{ {
$concat_key++; $concat_key++;
$concat_list[$concat_key][] = $file; $concat_list[$concat_key][] = $file;

View file

@ -24,7 +24,7 @@
<!-- JS --> <!-- JS -->
@foreach (Context::getJsFile('head', true) as $js_file) @foreach (Context::getJsFile('head', true) as $js_file)
<script src="{!! $js_file['file'] !!}"></script> <script src="{!! $js_file['file'] !!}"{!! $js_file['attrs'] !!}></script>
@endforeach @endforeach
<!-- RSS --> <!-- RSS -->