Giter Club home page Giter Club logo

Comments (6)

watarutmnh avatar watarutmnh commented on August 12, 2024 1

@khalwat Thank you sharing the issue thread.
I'm using valet so the @haytor 's comment are very helpful.
I created Local driver and put it on root directory of the project.

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.

from craft-vite.

watarutmnh avatar watarutmnh commented on August 12, 2024

Additional Info

The image src url 404 error got is https://appexample.test/src/logo.svg
But I can access the asset to https://localhost:3001/src/logo.svg

from craft-vite.

khalwat avatar khalwat commented on August 12, 2024

One way is to put the image in the /public dir in the Vite root. https://vitejs.dev/guide/assets.html#the-public-directory

Beyond that I'm not sure -- this is more of a ViteJS question though, so head over here: https://github.com/vitejs/vite/issues

from craft-vite.

khalwat avatar khalwat commented on August 12, 2024

Come to think of it, it could be related to this: vitejs/vite#2196

from craft-vite.

khalwat avatar khalwat commented on August 12, 2024

@watarutmnh I think we have a better solution as detailed here:

https://nystudio107.com/blog/using-vite-js-next-generation-frontend-tooling-with-craft-cms#vite-processed-assets

Issue ref: vitejs/vite#2394

from craft-vite.

watarutmnh avatar watarutmnh commented on August 12, 2024

@khalwat Good to know that! Thanks!

from craft-vite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.