-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
[Support] How to resolved static assets path imported in react components while dev server running #8
Comments
Additional InfoThe image src url 404 error got is https://appexample.test/src/logo.svg |
One way is to put the image in the Beyond that I'm not sure -- this is more of a ViteJS question though, so head over here: https://github.com/vitejs/vite/issues |
Come to think of it, it could be related to this: vitejs/vite#2196 |
@khalwat Thank you sharing the issue thread. LocalValetDriver.php <?php
class LocalValetDriver extends LaravelValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
// The host and port of the Vite dev server.
$host = 'localhost';
$port = 3001;
$timeout = 6;
// Use fsockopen to ping the server to determine if the driver will handle the request.
$fsock = @fsockopen($host, $port, $errno, $errstr, $timeout);
return is_resource($fsock) ? true : false;
}
/**
* Determine if the incoming request is for a static file.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string|false
*/
public function isStaticFile($sitePath, $siteName, $uri)
{
// Application root directory resource loading, resource reference in node_modules
if (file_exists($staticFilePath = $sitePath . '/' . $uri)
&& is_file($staticFilePath)) {
return $staticFilePath;
}
if (file_exists($staticFilePath = $sitePath . '/web' . $uri)
&& is_file($staticFilePath)) {
return $staticFilePath;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
return $sitePath . '/web/index.php';
}
} It seems to be working ok so far. |
@watarutmnh I think we have a better solution as detailed here: Issue ref: vitejs/vite#2394 |
@khalwat Good to know that! Thanks! |
Question
I'm trying out craft-vite with react component.
The assets path which imported in react components are resolved fine in production build, but they aren't while dev server running.
Is there any way I can solve it?
Thanks,
Example
#app.tsx
The text was updated successfully, but these errors were encountered: