You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-19Lines changed: 29 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,46 +6,56 @@ This package provides a helper to generate paths to assets on the client-side th
6
6
npm install @codinglabs/laravel-asset --save
7
7
```
8
8
9
-
Vue.js example:
9
+
Vue 3 global mixin:
10
10
```javascript
11
-
import {asset} from'@codinglabs/laravel-asset'
11
+
import { asset } from'@codinglabs/laravel-asset'
12
+
13
+
returncreateApp({ render: () =>h(app, props) })
14
+
// ...
15
+
.mixin({
16
+
methods: {
17
+
asset,
18
+
},
19
+
})
20
+
```
12
21
13
-
window.Vue=require('vue')
22
+
Vue 3 component example:
23
+
```vue
24
+
<script setup>
25
+
import { asset } from '@codinglabs/laravel-asset'
26
+
</script>
14
27
15
-
Vue.mixin({
16
-
methods: {
17
-
asset: asset
18
-
}
19
-
})
28
+
<template>
29
+
<img :src="asset('path/to/foo.jpg')">
30
+
</template>
20
31
```
21
32
22
33
## Usage
23
-
The package can be configured with a mix `.env` variable:
34
+
The asset prefix can be configured with an environment variable, or by setting an asset path on the server side in the document metadata.
35
+
36
+
If the asset url is unknown when building the app (ie. Laravel Vapor, where the asset URL is not generated until the deploy step), the metadata option can be used.
37
+
38
+
To configure with an `.env` variable:
24
39
25
40
```
26
41
ASSET_URL=https://foo.cloudfront.net
27
-
MIX_ASSET_URL="${ASSET_URL}"
42
+
VITE_ASSET_URL="${ASSET_URL}"
28
43
```
29
44
30
-
Or by adding a meta tag, which is handy if the `ASSET_URL` is determined at deployment time (like with Laravel Vapor):
To inject an asset into a Vuejs component, use a [dynamic prop](https://vuejs.org/v2/guide/components-props.html#Passing-Static-or-Dynamic-Props):
51
+
Once configured, simply call the `asset()` helper like you would when using the Laravel helper:
38
52
39
53
```html
40
54
<img:src="asset('path/to/foo.jpg')">
41
55
```
42
56
43
-
This will be prefixed with the asset URL the same as how the Laravel `asset()` helper works.
44
-
45
-
If you need to conditionally build against a specific environment file, take a look at [mix-env-file](https://github.com/johnwilhite/mix-env-file).
46
-
47
57
## About Coding Labs
48
-
Coding Labs is a web app development agency based on the Gold Coast, Australia. See our open source projects [on our website](https://codinglabs.io).
58
+
Coding Labs is a web app development agency based on the Gold Coast, Australia. See our open source projects [on our website](https://codinglabs.com.au).
49
59
50
60
## License
51
-
The MIT License (MIT). Please see [License File](LICENSE) for more information.
61
+
The MIT License (MIT). Please see [License File](LICENSE) for more information.
0 commit comments