How to install alpine-js in laravel

Laravel Alpine js using CDN

Step 1: First run command in your project directory :

>> npm install alpinejs

Step 2: import alpine js on app.js file:

resources/js/app.js

Step 3: Run command run dev command

npm run dev

Step 4 :  Use app.js file Comman Header Blade Section:

<script src="{{ asset('js/app.js') }}" defer></script>

 

Example Code: 

<div x-data="{ open: false }">    <button @click="open = true">Expand</button>     <span x-show="open">      Content...    </span></div>