Skip to content

Commit

Permalink
Add js_type config option (#59) (#60)
Browse files Browse the repository at this point in the history
* Add js_type config option (#59)

* Separate js asset types & update docs (#59)
  • Loading branch information
Thomva authored Feb 14, 2024
1 parent 012946b commit 3080e73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Default: `public_path('build/manifest.json')`

#### `assets`

An array of urls to the `css` and `js` used by your components. The `css` and `js` urls are seperated out as the `css` is included in the head and the `js` is included before the closing `body` tag.
An array of urls to the `css` and `js` used by your components. The `css` and `js` urls are seperated out as the `css` is included in the head and the `js` is included before the closing `body` tag. `js` assets can have [types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type) (default: `text/javascript`).

You can also group assets and specify which to use for different components.

Expand All @@ -173,11 +173,15 @@ You can also group assets and specify which to use for different components.
],
'js' => [
'path/to/default.js', // default, loaded in all stories
[ // load as a module
'path' => 'path/to/default.js',
'type' => 'module'
]
'blast' => 'path/to/blast.js', // load a single file
'area17' => [ // use array to load multiple files
'path/to/area17.js'
'path/to/area17-other.js'
]
],
]
]
```
Expand Down
14 changes: 13 additions & 1 deletion resources/views/storybook.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@

@if (!empty($js))
@foreach ($js as $key => $asset)
<script src="{{ $asset }}"></script>
@php
$path = $asset['path'] ?? (is_string($asset) ? $asset : null);
$type = $asset['type'] ?? null;
@endphp

@if ($path)
<script
@if ($type)
type="{{ $type }}"
@endif
src="{{ $path }}"
></script>
@endif
@endforeach
@endif
</body>
Expand Down

0 comments on commit 3080e73

Please sign in to comment.