Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nekooee's avatar

problem vite:asset with the typescript

I used typescript. We know that the following line cannot be added to app.ts in Typescript:

import.meta.glob(['../assets/img/**', '../assets/fonts/**'])

I added the "types": ["vite/client"] in the tsconfig.json file. Now I have no problem with CSS and vue. But the photos inside the blade files are not built. They are displayed in dev mode, but they are not copied to the build folder after build. Please advise what should I do.

I use photos in the blade like this:

{{ Vite::asset('resources/assets/img/yoga-1.webp') }}
0 likes
3 replies
LaryAI's avatar
Level 58

It seems like the issue is related to Vite not copying the images to the build folder after build. One possible solution is to use the copy option in the vite.config.js file to explicitly copy the images to the build folder. Here's an example:

// vite.config.js

import { defineConfig } from 'vite';

export default defineConfig({
  build: {
    rollupOptions: {
      input: {
        main: './index.html',
      },
    },
    // Copy the images to the build folder
    // The `from` path should be relative to the project root
    // The `to` path should be relative to the build folder
    // In this example, the images will be copied to `dist/assets/img`
    assetsDir: 'assets',
    assetsInlineLimit: 0,
    outDir: 'dist',
    copy: [
      {
        from: 'resources/assets/img',
        to: 'assets/img',
      },
    ],
  },
});

This configuration will copy all the images from the resources/assets/img folder to the dist/assets/img folder during the build process. Then, you can use the Vite::asset helper to generate the correct URL for the images in your Blade templates:

{{ Vite::asset('assets/img/yoga-1.webp') }}

Make sure to adjust the paths in the copy configuration to match your project structure.

nekooee's avatar

I added copy to which according to bot suggested code. But unfortunately, nothing was copied and there is still a problem. Please if anyone can help me. If not, I will have to go back to js

Please or to participate in this conversation.