laravel - laravel mix - svelte - tailwindcss - browser sync
Create laravel project in current director
composer create-project laravel/laravel . --prefer-dist
Node Module
npm i
Install laravel mix
npm install wewowweb/laravel-mix-svelte
Now we need to configure webpack.mix.js https://laravel-mix.com/extensions/svelte
const mix = require('laravel-mix');
require('laravel-mix-svelte');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.svelte({
dev: true
});
5 Open resources/js/app.js
import App from './components/App';
require('./bootstrap');
const app = new App({
target: document.querySelector('#svelte-app')
});
Since we are targeting html with the id of svelte-app Let’s open welcome.blade.php file and add a div with svelte-app id
<div id="svelte-app"></div>
Create a file resources/js/components/App.svelte & add some test code
Open welcome.blade.php file and add this code before closing the body tag
<script type="text/javascript" src="{{ asset('js/app.js')}}"></script>
Install tailwind
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
Open webpack.mix.js
mix.js("resources/js/app.js", "public/js")
.postCss("resources/css/app.css", "public/css", [
require("tailwindcss"),
]);
Configure tailwind.config.js
module.exports = {
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
"./resources/**/*.vue",
],
theme: {
extend: {},
},
plugins: [],
}
Open app.css
@tailwind base;
@tailwind components;
@tailwind utilities;
Add tailwind in html
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
Run
npm run watch
Run
php artisan serve
Open webpack.mix.js then add the following line
mix.browserSync(
{
proxy: 'http://127.0.0.1:8000',
}
)
Now
run npm watch
The first time it will install couple of packages & then run the same command again
Done, You have laravel live reload now