admin管理员组

文章数量:1416071

I started a new Laravel project and now Laravel Mix has been replaced with Vite.

I've installed Alpine.js and launched it in the bootstrap.js file but, Alpine.js not recognized in the Laravel blade files and the other JS files.

vite.config

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import  path from "path";
export default defineConfig({
    plugins: [
        laravel([
            'resources/css/app.css',
            'resources/js/app.js',
        ]),
    ],
    resolve:{
        alias:{
            '~alpine':path.resolve(__dirname,'node_modules/alpinejs'),
        }
    }
});

enter image description here

app.js

import './bootstrap';
import alpine from "./alpinejs/src/alpine";
console.log(alpine.version);

enter image description here

I started a new Laravel project and now Laravel Mix has been replaced with Vite.

I've installed Alpine.js and launched it in the bootstrap.js file but, Alpine.js not recognized in the Laravel blade files and the other JS files.

vite.config

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import  path from "path";
export default defineConfig({
    plugins: [
        laravel([
            'resources/css/app.css',
            'resources/js/app.js',
        ]),
    ],
    resolve:{
        alias:{
            '~alpine':path.resolve(__dirname,'node_modules/alpinejs'),
        }
    }
});

enter image description here

app.js

import './bootstrap';
import alpine from "./alpinejs/src/alpine";
console.log(alpine.version);

enter image description here

Share Improve this question edited Jul 22, 2022 at 1:11 user633440 asked Jul 21, 2022 at 20:06 hossein darvishihossein darvishi 411 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

I add Alpine like the following.

bootstrap.js

import _ from 'lodash';
window._ = _;

import $ from 'jquery';
window.jQuery = window.$ = $

import Alpine from 'alpinejs';
window.Alpine = Alpine;
Alpine.start();

本文标签: javascriptAlpinejs is not working in new Laravel and Vite instanceStack Overflow