Skip to content

Commit

Permalink
revert to Laravel Mix instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
stevethomas committed Dec 5, 2022
1 parent ab27312 commit 3f057a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Laravel Asset Helper
This package provides a helper to generate paths to assets on the client-side the same as in Laravel with `asset('foo.jpg')`.

Notices:
- This package works best with Laravel Mix; if you are using Vite, you should [bundle assets](https://laravel.com/docs/9.x/vite#blade-processing-static-assets) in the `resources` directory instead
- There is also an official asset helper for [Laravel Vapor](https://docs.vapor.build/1.0/projects/deployments.html#asset)

## Install
``` bash
npm install @codinglabs/laravel-asset --save
Expand Down Expand Up @@ -39,7 +43,7 @@ To configure with an `.env` variable:

```
ASSET_URL=https://foo.cloudfront.net
VITE_ASSET_URL="${ASSET_URL}"
MIX_ASSET_URL="${ASSET_URL}"
```

To configure with a meta tag in Laravel Blade:
Expand Down
14 changes: 7 additions & 7 deletions asset.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const asset = (path) => {
// default to VITE_ASSET_URL
let prefix = import.meta.env.VITE_ASSET_URL
// default to MIX_ASSET_URL
let prefix = process.env.MIX_ASSET_URL

if (!prefix) {
// fallback to determining ASSET_URL from meta tag
prefix = document.head.querySelector('meta[name="asset-url"]').content
}
if (!prefix) {
// fallback to determining ASSET_URL from meta tag
prefix = document.head.querySelector('meta[name="asset-url"]').content
}

return prefix.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
return prefix.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "@codinglabs/laravel-asset",
"version": "2.0.1",
"version": "1.0.4",
"description": "A helper to resolve paths to assets in a Laravel app",
"main": "asset.js",
"repository": {
Expand Down

0 comments on commit 3f057a8

Please sign in to comment.