Tailwind not getting imported in Laravel - laravel

I have a Laravel project and I'm trying to install Tailwind.
I have a tailwind.css file: \resources\assets\stylesheets\tailwind.css
#import "tailwindcss/base";
#import "tailwindcss/components";
#import "tailwindcss/utilities";
Which I import in:\resources\assets\stylesheets\index.css
#import "tailwind.css"
My webpack.mix.js file:
const mix = require('laravel-mix');
const tailwindcss = require('tailwindcss');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.options({
processCssUrls: false,
postCss: [ tailwindcss('./tailwind.config.js') ],
});
And tailwind.config.js:
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
When I run the app and check the generated http://localhost/dist/css/app.css I see this:
/* Import Tailwind*/
#tailwind base;
#tailwind components;
#tailwind utilities
I've installed tailwind through npm, can also find the tailwind folder in my node_modules folder.

Have you included index.css in your app.scss file?
You really don't need to put Tailwind through a sass parser if all you're doing is including the base styles etc. anyway.
Assuming you have Tailwind installed as a dependency already, you can include Tailwind in your project as follows:
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/assets/stylesheets/index.css', 'public/css', [
require('tailwindcss'),
]);

Related

i installed jetsream to fresh laravel project . but jetstream login and register pages are not in proper view

i installed jetstream in laravel 8 by using documentation but it not displayed proper way.
here is the tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
`/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('#tailwindcss/forms'), require('#tailwindcss/typography')],
};
First finish your installation then compile assets:
npm install
npm run dev
Php artisan migrate
Afterwards still if it did not work
At the style section of app.blade.php you might be missing:
<link rel="stylesheet" href="{{ mix('css/app.css') }}">

How to make tailwindcss custom color work in Laravel 9

I have installed tailwindcss in a Laravel 9 project and trying to add custom colors. Then added this in webpack.mix.js
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
require("tailwindcss"),
]);
To add the custom colors, I have added the colors in my tailwind.config.js file like this
const colors = require('tailwindcss/colors');
module.exports = {
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
"./resources/**/*.vue",
],
theme: {
color: {
transparent: 'transparent',
current: 'currentColor',
'blue': '#71BBE2',
'orange': '#E28333',
'black': '#242121',
'gray': '#242121CC',
'lemon': '#C3D14A',
'green': '#88B667',
'lime': '#F8FFF4',
'purple': '#9D2883',
'white': '#FFFFFF'
},
extend: {},
},
plugins: [],
}
I have npm run watch running and I can see that laravel mix compiled successfully. Now when I use bg-orange in my view file like this
<nav class="bg-orange">
<div class="mx-32 py-2">
//....
</div>
</nav>
the color does not show in the browser and looking at the dev tools I cannot see the color appended to the bg prefix
<nav class="bg-">
<div class="mx-32 py-2">
//....
</div>
</nav>
Any idea what the issue could be?
Change color to colors.
theme: {
// the line below
color: { ...

How can I create and configure multiple Vue Instance in Laravel Mix?

I have a PHP project with Laravel and Vue.js
I want to handle Admin and Client separately. So I need to add 1 Vue Instance. But I don't know how to create and configure it. Please help me to solve this problem. Thank you very much.
mix
.js('resources/js/admin.js', 'public/js').vue()
.js('resources/js/client.js', 'public/js').vue()
On your blade file, inject proper js file like:
#if (str_contains(Route::currentRouteName(), "admin"))
<script src="{{ asset('js/admin.js') }}" defer></script>
#else
<script src="{{ asset('js/clients.js') }}" defer></script>
mix.js('resources/front/js/app.js', 'public/js').vue()
.sass('resources/front/css/app.scss', 'public/css')
.options({
autoprefixer: {
options: {
browsers: [
'last 6 versions',
]
}
}
})
mix.browserSync('your_site')
mix.js('resources/admin/js/adminapp.js', 'public/js').vue()
.sass('resources/admin/css/adminapp.scss', 'public/css')
.options({
autoprefixer: {
options: {
browsers: [
'last 6 versions',
]
}
}
})
mix.browserSync('your_site/admin')

GlobalVueStyles: not working for global Sass in vue components

I am trying to load a global sass variable file into my Vue style tags. If I am understanding globalVueStyles right, this should Indicate a file to include in every component style. But when I set it up it seems to not do anything and when I run npm run dev I get an undefined variable error.
Here is my laravel mix code:
mix.js('resources/js/app.js', 'public/js')
.vue()
.sass('resources/sass/main.scss', 'public/css')
.options({
extractVueStyles: true,
globalVueStyles: 'resources/sass/utils/_variables.scss',
})
.version()
after doing this I thought I should have access to my variables in my .vue files by doing this:
<template>
<h1>Example Component hi test</h1>
</template>
<script>
export default {
}
</script>
<style lang="scss">
h1 {
font-size: 50px;
color: $blue;
}
</style>
And here is the error I am getting:
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
4 │ color: $blue;
│ ^^^^^
╵
resources/js/components/HelloWorld.vue 4:11 root stylesheet
I'm sure I'm missing something, but any help on this would be appreciated.
I was led to answer from https://github.com/JeffreyWay/laravel-mix/issues/2896;
they seemed to upgrade the syntax the documentation can be found here:
https://github.com/JeffreyWay/laravel-mix/blob/467f0c9b01b7da71c519619ba8b310422321e0d6/UPGRADE.md#vue-configuration
When I tried your solution it did not work.
Here is how I managed to fix this issue, using this new/changed property additionalData, in previous versions this property was data or prependData.
mix.webpackConfig({
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: "sass-loader",
options: {
additionalData: `#import "#/_variables.scss";
#import "#/_mixins.scss";
#import "#/_extends.scss";
#import "#/_general.scss";`
},
},
],
}
]
},
resolve: {
alias: {
'#': path.resolve('resources/sass'),
'~': path.resolve('/resources/js'),
'Vue': 'vue/dist/vue.esm-bundler.js',
}
},
output: {
chunkFilename: '[name].js?id=[chunkhash]',
},
});
mix.js('resources/js/app.js', 'public/js').vue()
.sass('resources/sass/app.scss', 'public/css')
.copyDirectory('resources/images', 'public/images');
if (mix.inProduction()) {
mix.version();
}
Note that alias for path 'resources/scss' is "#".
I hope this saved someone some time :)

How to configure material components web with laravel-mix?

I use mdc with laravel-mix but it's not loading scss files from node modules.
I tried some other solutions about giving includepaths in mix.sass, but they are not working.
I tried code in webpack.mix.js
const path = require('path');
let mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css', {
includePaths: ['./node_modules']
});
but its still giving me same error that
undefined
^
Can't find stylesheet to import. #import "#material/elevation/mixins";
For Laravel 6 I had to do it this way:
npm install --save material-components-web
app.scss:
#import "material-components-web/material-components-web";
webpack.mix.js:
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css', {
sassOptions: {
includePaths: ['./node_modules']
}
});
Yes, answer from Edmund Sulzanok is correct, add sassOptions but for me too:
Laravel VERSION = '6.7.0';
I had to upgrade npm package.json devDependencies
"devDependencies": {
...
"cross-env": "^6.0.3",
"laravel-mix": "^5.0.1",
...,
"resolve-url-loader": "^3.1.1",
"sass": "^1.25.0",
"sass-loader": "^8.0.2",
...
},
"dependencies": {
...
"material-components-web": "^4.0.0",
...
}
After modify package.json run npm install
npm install
You could see Packages outdated with
npm outdated
good luck

Resources