-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.x] Vite custom cdn support #49378
Conversation
assetsUrl added to be able to pass custom cdn `@vite('resources/sass/app.scss', assetsUrl: 'https://cdn.domain/')`
@AmirHossein can you not set the |
in my case, asset url is not static and resources are distributed to different servers. so it would be great to support such cases... |
This would be handy for multi tenant apps where the asset URL is determined dynamically. |
Would you just do the following in your tenant "setup" to achieve this? Config::set('app.asset_url', '...some dynamic URL here based on the tenant...'); The |
Ah, sorry, left out a key bit of info. We do the above for tenant subdomain assets. However, we serve bundles from our root domain. We currently do this by registering a modified Illuminate\Foundation\Vite with assetPath() overridden - so this would just be a nice to have from an upgradability perspective rather than necessary for our use case. And I cannot imagine it would be affected by upgrades much if it at all...! |
Hey folks, Would something like the following work for your needs? Similar to how we currently handle advanced customisations: https://laravel.com/docs/10.x/vite#advanced-customization <head>
<!-- ... -->
{{
Vite::withEntryPoints(['resources/js/app.js'])
->createAssetUrlsUsing(function ($path) {
// Custom logic here.
})
}}
</head> I'm not sure the current proposed solution is how we want to handle this. But could one of you also provide a bit more detail on why the feature is needed with the other things I've mentioned. Still not quite sure I get the setup that actually requires this change. Thanks! |
That would work for our use case. For us, any assets unique to a tenant are served from the tenant's domain using the asset_url config. Vite bundles are on the root domain only (and are the only thing on the root domain), which we use a CDN for. So we only override the Vite asset path. Amir's use case sounds different, though. FWIW in case you choose not to implement this and anyone is looking for an alternative, we currently just do this (The global_asset function is just a custom helper, that builds the URL in a similar way to asset):
and then in the AppServiceProvider:
|
Hi, We currently override assetPath method like @ChrisB-TL but asked for support officially, if possible. As Vite::createAssetUrlsUsing(function ($path) {
// Custom logic here.
}) |
Hey folks, I've created #49437 Could you confirm this solves your problems. Note that it does not allow you to customize the "hot" path generation, i.e., when the dev server is running, only the built asset paths. Let me know your thoughts. |
assetsUrl added to be able to pass custom cdn.
to have output like this: