1

In prior versions of Laravel, I moved code with custom JS files into webpack.mix.js. Is there a way to make a similar one in Laravel 9, which uses vite.config.js?

mix.copy('resources/js/custom-file.js', 'public/js/').version();
Atena Dadkhah
  • 623
  • 1
  • 5
  • 19
Petro Gromovo
  • 1,755
  • 5
  • 33
  • 91
  • why do not just use _window.myfunction = myfunction_ in you custom-file.js and use @vite call in in your blade.php file… see https://stackoverflow.com/a/76712996/6614155 – bcag2 Jul 18 '23 at 13:02

2 Answers2

0

I modified file vite.config.js:

import { viteStaticCopy } from 'vite-plugin-static-copy'

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [


        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),



        viteStaticCopy({
            targets: [
                {
                    src: 'resources/js/feedback.js',
                    dest: 'js/custom.js'
                }
            ]
        })


    ],
});

That helped me with my issue...

Petro Gromovo
  • 1,755
  • 5
  • 33
  • 91
0

viteStaticCopy does not add entry in manifest.json