|
27 | 27 | - [Subresource Integrity (SRI)](#subresource-integrity-sri)
|
28 | 28 | - [Arbitrary Attributes](#arbitrary-attributes)
|
29 | 29 | - [Advanced Customization](#advanced-customization)
|
| 30 | + - [Correcting Dev Server URLs](#correcting-dev-server-urls) |
30 | 31 |
|
31 | 32 | <a name="introduction"></a>
|
32 | 33 | ## Introduction
|
@@ -792,3 +793,42 @@ export default defineConfig({
|
792 | 793 | },
|
793 | 794 | });
|
794 | 795 | ```
|
| 796 | + |
| 797 | +<a name="correcting-dev-server-urls"></a> |
| 798 | +### Correcting Dev Server URLs |
| 799 | + |
| 800 | +Some plugins within the Vite ecosystem assume that URLs which begin with a forward-slash will always point to the Vite dev server. However, due to the nature of the Laravel integration, this is not the case. |
| 801 | + |
| 802 | +For example, the `vite-imagetools` plugin outputs URLs like the following while Vite is serving your assets: |
| 803 | + |
| 804 | +```html |
| 805 | +<img src="/@imagetools/f0b2f404b13f052c604e632f2fb60381bf61a520"> |
| 806 | +``` |
| 807 | + |
| 808 | +The `vite-imagetools` plugin is expecting that the output URL will be intercepted by Vite and the plugin may then handle all URLs that start with `/@imagetools`. If you are using plugins that are expecting this behaviour, you will need to manually correct the URLs. You can do this in your `vite.config.js` file by using the `transformOnServe` option. |
| 809 | + |
| 810 | +In this particular example, we will append the dev server URL to all occurrences of `/@imagetools` within the generated code: |
| 811 | + |
| 812 | +```js |
| 813 | +import { defineConfig } from 'vite'; |
| 814 | +import laravel from 'laravel-vite-plugin'; |
| 815 | +import { imagetools } from 'vite-imagetools'; |
| 816 | +
|
| 817 | +export default defineConfig({ |
| 818 | + plugins: [ |
| 819 | + laravel({ |
| 820 | + // ... |
| 821 | + transformOnServe: (code, devServerUrl) => code.replaceAll('/@imagetools', devServerUrl+'/@imagetools'), |
| 822 | + }), |
| 823 | + imagetools(), |
| 824 | + ], |
| 825 | +}); |
| 826 | +``` |
| 827 | + |
| 828 | +Now, while Vite is serving Assets, it will output URLs that point to the Vite dev server: |
| 829 | + |
| 830 | +```html |
| 831 | +- <img src="/@imagetools/f0b2f404b13f052c604e632f2fb60381bf61a520"><!-- [tl! remove] --> |
| 832 | ++ <img src="http://[::1]:5173/@imagetools/f0b2f404b13f052c604e632f2fb60381bf61a520"><!-- [tl! add] --> |
| 833 | +``` |
| 834 | + |
0 commit comments