Pharaonic / livewire-select2

Simple way to handle the Select2 for livewire components.
https://pharaonic.io/packages/livewire/select2
MIT License
37 stars 11 forks source link

How to make this work with Vite: getting "$ is not a function" #13

Open jordanade opened 5 months ago

jordanade commented 5 months ago

No matter how I configure my vite.config.js file, I get "$ is not a function" from livewire-select2's scripts. I've tried:

import inject from '@rollup/plugin-inject';

export default defineConfig({
    plugins: [
        inject({
            $: 'jquery',
            jQuery: 'jquery',
        }),
        ...

and

    optimizeDeps: {
        include: ["jquery"],
    },

and

    build: {
        rollupOptions: {
            output: {
                // expose jQuery as a global variable
                globals: {
                    $: 'jquery',
                    jQuery: 'jquery',
                    'window.jQuery': 'jquery',
                }
            }
        }
    }

With my old webpack/mix setup I was able to make this work with:

mix.webpackConfig(webpack => {
    return {
        plugins: [
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                'window.jQuery': 'jquery'
            }),
        ],
    };
});