javascript - Alpine.js is not working in new Laravel and Vite instance - Stack Overflow

I started a new Laravel project and now Laravel Mix has been replaced with Vite.I've installed Al

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();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745245875a4618407.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信