Laravel Mix and Tailwind CSS - laravel

I installed Tailwind using a tutorial and tried working around with a custom tailwind config file, but when I try to add first, last, or group pseudo-classes, it doesn't affect the CSS. I also previously noticed this with inset, and I added the inset section manually. Am I missing anything in config or Mix?
Tailwind config file
const { rotate } = require('tailwindcss/defaultTheme');
const defaultTheme = require('tailwindcss/defaultTheme');
module.exports = {
purge: [
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
cursor: {
'none': 'none'
},
opacity: {
'0': '0',
'25': '.25',
'50': '.5',
'75': '.75',
'10': '.1',
'20': '.2',
'30': '.3',
'40': '.4',
'50': '.5',
'60': '.6',
'70': '.7',
'80': '.8',
'90': '.9',
'100': '1',
},
zIndex: {
'-1' : -1,
'0': 0,
'10': 10,
'20': 20,
'30': 30,
'40': 40,
'50': 50,
'25': 25,
'50': 50,
'75': 75,
'100': 100,
'auto': 'auto',
},
inset: (theme, { negative }) => ({
auto: 'auto',
...theme('spacing'),
...negative(theme('spacing')),
'1/2': '50%',
'1/3': '33.333333%',
'2/3': '66.666667%',
'1/4': '25%',
'2/4': '50%',
'3/4': '75%',
full: '100%',
'-1/2': '-50%',
'-1/3': '-33.333333%',
'-2/3': '-66.666667%',
'-1/4': '-25%',
'-2/4': '-50%',
'-3/4': '-75%',
'-full': '-100%',
}),
colors: {
white:'#ffffff',
gray: {
100: "#D2D2D2",
200: "#BCBCBC",
300: "#A5A5A5",
400: "#8F8F8F",
500: "#797979",
600: "#626262",
700: "#4C4C4C",
800: "#353535",
900: "#1F1F1F",
},
orange: {
100: "#FFDFCC",
200: "#FFCFB3",
300: "#FFBF99",
400: "#FFB080",
500: "#FFA066",
600: "#FF904D",
700: "#FF8033",
800: "#FF701A",
900: "#FF6000",
},
},
rotate:{
'-180': '-180deg',
'-90': '-90deg',
'-45': '-45deg',
'0': '0',
'45': '45deg',
'90': '90deg',
'135': '135deg',
'180': '180deg',
'270': '270deg',
'360': '360deg'
},
borderWidth: {
DEFAULT: '1px',
'0': '0',
'2': '2px',
'3': '3px',
'4': '4px',
'6': '6px',
'8': '8px',
'10': '10px',
'12': '12px',
'14': '14px',
'16': '16px'
},
extend: {
height:{
'5.5/6': '91.6667%'
},
fontFamily: {
sans: ['Arial', ...defaultTheme.fontFamily.sans],
},
transitionDuration: {
'2000': '2000ms',
'3000' : '3000ms',
},
transitionProperty: {
'top': 'top',
'left': 'left',
},
lineHeight:{
12 : '3rem',
13: '3.25rem',
14: '3.5rem'
},
},
},
variants: (theme) => ({
...theme('variants'),
padding: ['first','last'],
margin: ['first','last'],
backgroundColor: ['first'],
textColor: ['first'],
outline: ['active','focus'],
position: ['first','last'],
opacity: ['responsive', 'hover', 'focus', 'disabled'],
borderRadius: ['hover', 'focus'],
width:['group-hover']
}),
plugins: [
require('#tailwindcss/ui'),
],
};
Laravel Mix File
const mix = require('laravel-mix');
const atImport = require('postcss-import');
const tailwindcss = require('tailwindcss');
mix.browserSync('localhost:8000');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.js('resources/js/admin.js','public/js')
.sass('resources/scss/app.scss', 'public/css')
.sass('resources/scss/admin.scss','public/css')
.options({
processCssUrls: false,
postCss: [
atImport(),
tailwindcss('./tailwind.config.js')
],
})
.webpackConfig(require('./webpack.config'));

I am not an expert in this but have used Tailwind CSS from pre V1. I notice that you are trying to use features from V2, (eg darkmode).
Several issues:
purge: [
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
purge: [],
does the second purge: [ ] clear the first array?
My tailwind.config.js file does not have the first 2 lines ending with require('tailwindcss/defaultTheme');
I have no idea what these are referencing, but do you not have your source folders for js included in the purge list. Add this line to the purge list if your javascript adds classes
.resources/js/**/*.js
As for the webpack.mix.js file my last lines are
.options({
processCssUrls: false,
postCss: [ tailwindcss('./tailwind.config.js') ],
});
Sorry but I am not an expert

Related

chartJS not showing the data

I am new to Laravel and ChartJS. Working on home project for farm management. I need to show annual milk generation ( monthwise) in chart. While Trying to show data in chartJS but not able to show the same.
The code is as below.
Data for Chart
var buffalototalmilkannual = JSON.parse('{!! json_encode($annualmilkrecord) !!}');
var monthsforbuffalototalmilkannual = JSON.parse('{!! json_encode($getmonths) !!}'); // Annual dates on x axis
//console.log(buffalototalmilkannual);
Chart
$(function () {
'use strict'
var annualbuffaloidmilkCanvas = $('#buffaloidmilkchartforyear').get(0).getContext('2d')
var annualbuffaloidmilkdata = {
labels: monthsforbuffalototalmilkannual,
datasets: [
{
label: 'Total Milk Prodcued',
backgroundColor: 'rgba(40, 167, 69, 0.9)',
borderColor: 'rgba(40, 167, 69, 0.8)',
pointRadius: false,
pointColor: '#3b8bba',
pointStrokeColor: 'rgba(40, 167, 69, 1)',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(40, 167, 69, 1)',
fill: false,
tension: 0.1,
pointRadius: 3,
data: 'buffalototalmilkannual',
},
]
}
var annualbuffaloidmilkOptions =
{
maintainAspectRatio: false,
responsive: true,
legend: { display: true },
scales:
{
xAxes: [{
gridLines: {
display: true,
},
type: 'time',
time: {
unit: 'month',
tooltipFormat: 'M Y'
}
}],
yAxes: [{
gridLines: {
display: true,
},
scaleLabel: {
display: true,
labelString: 'Milk in Liter'
},
ticks: {
suggestedMin: 0,
suggestedMax: 50
}
}],
},
tooltips: {enabled: true},
}
// This will get the first returned node in the jQuery collection.
// eslint-disable-next-line no-unused-vars
var salesChart = new Chart(annualbuffaloidmilkCanvas,
{
type: 'line',
data: annualbuffaloidmilkdata,
options: annualbuffaloidmilkOptions
}
)
})
Console.log file
Array(12)
0: "12.00"
1: "11.75"
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 0
9: 0
10: 0
11: 0
length: 12
Did i miss something. Same code is working in another blade file for other data.
Thanks in Advance

How to use two different tailwind config on laravel project

I am using a admin template on one of my laravel project and here are the files:
tailwind.config.js
const colors = require("tailwindcss/colors");
const {
toRGB,
withOpacityValue,
} = require("#left4code/tw-starter/dist/js/tailwind-config-helper");
module.exports = {
mode: "jit",
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
"./resources/**/*.jsx",
"./resources/**/*.vue",
],
theme: {
extend: {
colors: {
rgb: toRGB(colors),
primary: withOpacityValue("--color-primary"),
secondary: withOpacityValue("--color-secondary"),
success: withOpacityValue("--color-success"),
info: withOpacityValue("--color-info"),
warning: withOpacityValue("--color-warning"),
pending: withOpacityValue("--color-pending"),
danger: withOpacityValue("--color-danger"),
light: withOpacityValue("--color-light"),
dark: withOpacityValue("--color-dark"),
slate: {
50: withOpacityValue("--color-slate-50"),
100: withOpacityValue("--color-slate-100"),
200: withOpacityValue("--color-slate-200"),
300: withOpacityValue("--color-slate-300"),
400: withOpacityValue("--color-slate-400"),
500: withOpacityValue("--color-slate-500"),
600: withOpacityValue("--color-slate-600"),
700: withOpacityValue("--color-slate-700"),
800: withOpacityValue("--color-slate-800"),
900: withOpacityValue("--color-slate-900"),
},
darkmode: {
50: withOpacityValue("--color-darkmode-50"),
100: withOpacityValue("--color-darkmode-100"),
200: withOpacityValue("--color-darkmode-200"),
300: withOpacityValue("--color-darkmode-300"),
400: withOpacityValue("--color-darkmode-400"),
500: withOpacityValue("--color-darkmode-500"),
600: withOpacityValue("--color-darkmode-600"),
700: withOpacityValue("--color-darkmode-700"),
800: withOpacityValue("--color-darkmode-800"),
900: withOpacityValue("--color-darkmode-900"),
},
},
fontFamily: {
roboto: ["Roboto"],
},
container: {
center: true,
},
maxWidth: {
"1/4": "25%",
"1/2": "50%",
"3/4": "75%",
},
strokeWidth: {
0.5: 0.5,
1.5: 1.5,
2.5: 2.5,
},
},
},
plugins: [require("#tailwindcss/forms")],
variants: {
extend: {
boxShadow: ["dark"],
},
},
}
and this, is my current webpack.mix.js
const mix = require('laravel-mix');
mix.js('resources/admin-template/js/app.js', 'public/assets/js/admin-template.js')
.js('resources/js/app.js', 'public/assets/js')
.react()
.sass('resources/sass/app.scss', 'public/assets/css')
.postCss("resources/admin-template/css/app.css", "public/assets/css/admin-template.css");
and here is my current postcss.config.js
module.exports = {
plugins: [
require("postcss-import"),
require("postcss-advanced-variables"),
require("tailwindcss/nesting"),
require("tailwindcss")("./tailwind.config.js"),
require("autoprefixer"),
],
};
Now, I had separately created frontend design, and it has this tailwind.config.js
module.exports = {
content: ['./*.html'],
theme: {
extend: {
colors: {
'primary': '#1A1C29',
'primary-light': '#2A2D3E',
'theme-blue': '#2563eb',
'theme-green': '#06D594',
'light-gray': '#999ba6',
'yellow': '#FFFF00',
'gold': '#facc15',
'red': '#FF0000'
},
fontFamily:{
'poppins': ['Poppins', 'sans-serif'],
'roboto' : ['Roboto', 'sans-serif']
},
fontSize:{
'xxs': '.63rem',
},
screens:{
'sm': '575px',
},
},
},
}
Now, I have this css on resources/css/front.css, now how could I compile on this laravel project by using this second tailwind config value for front .css only.
I have tried this by adding this line on webpack. But, its not compiling correctly, its using different colors combination.
.postCss("resources/css/front.css", "public/assets/css/front.css");
What would be the best and safest to handle this scenario with single tailwind.config.js
If merging both tailwind.config.js files is not an option, calling mix.postCss twice is one way to do it.
The postCss method accepts an array of PostCSS plugins. This allows you to pass tailwindcss with a different configuration file.
webpack.mix.js
const mix = require('laravel-mix');
mix.postCss('resources/css/app.css', 'public/css', [
require('tailwindcss')('tailwind.config.js')
]);
mix.postCss('resources/css/front.css', 'public/css', [
require('tailwindcss)('tailwind-front.config.js')
]);
In that case I'd suggest removing the postcss.config.js file from your project and providing the array of plugins manually for each calls to postCss.
webpack.mix.js
const mix = require('laravel-mix');
mix.postCss('resources/css/app.css', 'public/css', [
require("postcss-import"),
require("postcss-advanced-variables"),
require("tailwindcss/nesting"),
require('tailwindcss')('tailwind.config.js'),
require("autoprefixer"),
]);
mix.postCss('resources/css/front.css', 'public/css', [
require("postcss-import"),
require("postcss-advanced-variables"),
require("tailwindcss/nesting"),
require('tailwindcss')('tailwind-front.config.js'),
require("autoprefixer"),
]);

Problem compiling SASS with Laravel Mix and Tailwind

I am trying to compile SASS files in my mix.config.js, but I have not succeeded.
talwind.config.js
const primaryColors = require("./colors");
module.exports = {
purge: [
'./resources/**/*.blade.php',
'./resources/**/*.js',
'./resources/**/*.vue',
],
darkMode: "class",
theme: {
borderColor: theme => ({
...theme("colors"),
DEFAULT: primaryColors.gray["300"]
}),
extend: {
colors: {
...primaryColors,
theme: {
1: "#1C3FAA",
2: "#F1F5F8",
3: "#2E51BB",
4: "#274AB7",
5: "#DEE7EF",
6: "#D32929",
7: "#365A74",
8: "#D2DFEA",
9: "#91C714",
10: "#3160D8",
11: "#F78B00",
12: "#FBC500",
13: "#7F9EB9",
14: "#E6F3FF",
15: "#8DA9BE",
16: "#607F96",
17: "#FFEFD9",
18: "#D8F8BC",
19: "#2449AF",
20: "#395EC1",
21: "#C6D4FD",
22: "#E8EEFF",
23: "#1A389F",
24: "#163296",
25: "#C7D2FF",
26: "#15329A",
27: "#203FAD",
28: "#BBC8FD",
29: "#284EB2",
30: "#98AFF5"
}
},
fontFamily: {
roboto: ["Roboto"]
},
container: {
center: true
},
maxWidth: {
"1/4": "25%",
"1/2": "50%",
"3/4": "75%"
},
screens: {
sm: "640px",
md: "768px",
lg: "1024px",
xl: "1280px",
xxl: "1600px"
},
strokeWidth: {
0.5: 0.5,
1.5: 1.5,
2.5: 2.5
}
}
},
variants: {
extend: {
zIndex: ["responsive", "hover"],
position: ["responsive", "hover"],
padding: ["responsive", "last"],
margin: ["responsive", "last"],
borderWidth: ["responsive", "last"],
backgroundColor: ["last", "first", "odd", "responsive", "hover", "dark"],
borderColor: ["last", "first", "odd", "responsive", "hover", "dark"],
textColor: ["last", "first", "odd", "responsive", "hover", "dark"],
boxShadow: ["last", "first", "odd", "responsive", "hover", "dark"],
borderOpacity: ["last", "first", "odd", "responsive", "hover", "dark"],
backgroundOpacity: ["last", "first", "odd", "responsive", "hover", "dark"]
}
}
};
webpack.config.js
const path = require('path');
module.exports = {
resolve: {
alias: {
'#': path.resolve('resources/js'),
},
}
};
webpack.mix.js
const mix = require('laravel-mix');
require('laravel-mix-postcss-config');
const tailwindcss = require('tailwindcss')
mix.js('resources/js/app.js', 'public/dist/js')
.sass('resources/js/assets/sass/app.scss', 'public/dist/css', {}, [
require('tailwindcss')
])
.options({
processCssUrls: false,
postCss: [
tailwindcss('./tailwind.config.js'),
]
})
.autoload({ 'cash-dom': ['$', 'cash'] })
.copyDirectory('resources/js/assets/images', 'public/dist/images')
.copyDirectory('node_modules/summernote/dist/font/summernote.woff', 'public/dist/fonts/summernote')
.browserSync({
proxy: 'evpiu.test',
files: ['resources/**/*.*']
}).webpackConfig(require('./webpack.config'));
if (mix.inProduction()) {
mix.version();
}
I'm getting the following error. Does anyone have an idea how to fix this? I have not been able to get it to work in any way. I am not a Laravel mix Expert, so it is a big problem for me.
From what the error says, I think you are not suppose to add "dark" to the variants -> extend.

Strange output when building Tailwind through PostCSS (Laravel Mix)

I'm using Laravel Mix and PostCSS to build Tailwind.
Everything works, I can even Purge unused styles.
I have strange outputs when I build (a LOT of these) :
--tw-space-y-reverse [
{
index: 40,
token: '-',
type: 9,
eval: [Function: sub],
precedence: 1,
show: '-'
},
{
index: 40,
token: '-',
type: 9,
eval: [Function: sub],
precedence: 1,
show: '-'
}
]
I'm using the latest TailwindCSS version.
Here is the relevant part of my webpack.mix.js :
const mix = require('laravel-mix');
require('laravel-mix-purgecss');
let tailwindcss = require('tailwindcss');
mix.postCss('resources/css/tailwind.css', 'public/css/soumettre202101.css', [
tailwindcss('./tailwind.config.js'),
]);
I don't even know where to start. I don't know what's causing this.
Any lead will be appreciated!
I can remove the output by disabling this core plugins (in my tailwind.config.js) :
module.exports = {
corePlugins: {
space: false,
ringWidth: false,
ringColor: false,
ringOffsetWidth: false,
ringOffsetColor: false,
ringOpacity: false,
divideOpacity: false,
divideColor: false,
divideWidth: false,
}
}
Even more strange : if I only disable "space", the output changes from the one above to the same thing but with --tw-ring-width-reverse, as if the last plugin used produces the output...
I'm not sure if that helps, but I will show you my config that seems to be working fine (using Sass), I removed some irrelevant parts.
webpack.mix.js
const mix = require('laravel-mix');
const tailwindcss = require('tailwindcss');
mix.sass('resources/sass/tailwind.scss', 'public/css')
.options({
processCssUrls: false,
postCss: [ tailwindcss('./resources/tailwind.config.js') ],
})
.version();
tailwind.scss
#import "~tailwindcss/base";
#import "~tailwindcss/components";
#import "~tailwindcss/utilities";
and finally tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
const colors = require('tailwindcss/colors');
module.exports = {
purge: {
content: [
'./resources/views/**/*.blade.php',
'./resources/js/**/*.js',
],
defaultExtractor: content => content.match(/[\w-/.:]+(?<!:)/g) || []
},
theme: {
extend: {
fontFamily: {
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
},
colors: {
// some custom colors
gray: colors.trueGray,
indigo: colors.indigo,
red: colors.rose,
yellow: colors.amber,
bluegray: colors.blueGray,
orange: colors.amber,
teal: colors.teal,
pink: colors.pink,
green: colors.green,
},
},
},
variants: {
gridColumn: ['responsive', 'hover'],
gridColumnStart: ['responsive', 'hover'],
gridColumnEnd: ['responsive', 'hover'],
},
plugins: [
require('tailwindcss'),
require('autoprefixer'),
require('#tailwindcss/forms'),
require('#tailwindcss/typography'),
require('#tailwindcss/aspect-ratio'),
],
};
When I run nom run dev everything seems to be fine, there is no output like you showed but I have things like this:
.space-y-11 > :not([hidden]) ~ :not([hidden]){
--tw-space-y-reverse: 0;
margin-top: calc(2.75rem * calc(1 - var(--tw-space-y-reverse)));
margin-bottom: calc(2.75rem * var(--tw-space-y-reverse));
}
Obviously later only those that are really used in blade/js files are in final file when I run npm run prod
The problem has been solved by ugrapding Laravel Mix to the latest version.

Can't disable auto-download in version 4.3

My config is:
self.editor = new $window.PhotoEditorSDK.UI.ReactUI({
container,
responsive: true,
license: JSON.stringify(sdkLicenseData),
assets: {
baseUrl: '/dist/photoeditorsdk/assets/',
},
editor: {
image: img,
},
style: {
width: 800,
height: 800,
},
enableExport: true,
export: {
type: $window.PhotoEditorSDK.ImageFormat.IMAGE,
quality: 1.0,
download: false,
},
});
I'm able to detect export being clicked by:
self.editor.on('export', (newUrl) => {
.. but it still downloads the image. How can this be disabled?
I've also tried:
self.editor.on('export', (newUrl) => {
self.editor.export(false)
.then((data) => {
const foo = 1;
});
...but again, by the time I execute the 2nd line, an image has already been downloaded.
The export field here must be inside the editor option, e.g.,
self.editor = new $window.PhotoEditorSDK.UI.ReactUI({
container,
responsive: true,
license: JSON.stringify(sdkLicenseData),
assets: {
baseUrl: '/dist/photoeditorsdk/assets/',
},
editor: {
image: img,
export: {
type: $window.PhotoEditorSDK.ImageFormat.IMAGE,
quality: 1.0,
download: false,
}
},
style: {
width: 800,
height: 800,
},
enableExport: true
})
Then is should work.

Resources