Build separate CSS files using Tailwindcss and laravel-vite-plugin - laravel

I'm trying to build two separate CSS files using Tailwindcss, Laravel and vite-plugin.
The two css files use different configuration, but I have no idea how specify the correct tailwind.config.js for each builds.
app.css should use tailwind.config.js
mail.css should use tailwind-mail.config.js
vite.config.js
import { defineConfig } from "vite"
import laravel from "laravel-vite-plugin"
export default defineConfig({
plugins: [
laravel({
input: ["resources/css/app.css", "resources/js/app.js", "resources/css/mail.css"]
refresh: true,
})
]
})
postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
tailwind.config.js
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: {},
plugins: [require("#tailwindcss/forms"), require("#tailwindcss/typography")],
}
tailwind-mail.config.js
module.exports = {
content: ["./resources/views/mails/**/*.blade.php"],
theme: {},
plugins: [require("#tailwindcss/typography")],
}

I haven't try myself yet, but reading the release notes of Tailwind CSS v3.2 it should be fairly easy to split into two CSS files using #config <filename>:
app.css
#config "./tailwind.config.js";
#tailwind base;
#tailwind components;
#tailwind utilities;
mail.css
#config "./tailwind.mail.config.js";
#tailwind base;
#tailwind components;
#tailwind utilities;
vite.config.js
import { defineConfig } from "vite"
import laravel from "laravel-vite-plugin"
export default defineConfig({
plugins: [
laravel({
input: ["resources/css/app.css", "resources/js/app.js", "resources/css/mail.css"]
refresh: true,
})
]
})

Related

Laravel 9 tailwind.css with vite

I have troubles using tailwind.css when install according to https://tailwindcss.com/docs/guides/laravel
When trying to run npm run dev
Error: failed to load config from vite.config.js
error when starting dev server:
Error: Cannot find module 'node:path' is thrown.
tailwind.config.js:
module.exports = {
content: [
 './resources//*.blade.php',
 './resources//.js',
 './resources/**/.vue',
 './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
],
theme: {
 extend: {},
},
 plugins: [],
}
vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
 plugins: [
  laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
  refresh: true,
 }),
 ],
});
app.css:
#tailwind base;
#tailwind components;
#tailwind utilities;

Tailwind missing classes after update from v2 to v3 Laravel 8

I updated tailwind from v2 to v3 and now some classes are missing. I have tried to reinstall tailwind and its dependencies, but it did not help.
What is causes such strange behaviour?
Example:
w-6/12
w-7/12 <- does not exist
w-8/12
w-9/12
w-10/12
w-11/12 <- does not exist
w-12/12 <- does not exist
And other classes from grid, fonts-sizes, etc.
Versions
tailwindcss: 3.0.15
tailwindcss/aspect-ratio: 0.4.0
tailwindcss/forms: 0.4.0
tailwindcss/line-clamp: 0.3.1
tailwindcss/typography: 0.5.0
tailwind.config.js
const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
content: [
'./storage/framework/views/*.php',
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./vendor/laravel/jetstream/**/*.blade.php',
'./resources/views/**/*.blade.php',
],
prefix: 'tw-',
theme: {
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
backgroundColor: theme => ({
...theme('colors'),
'header': '#ffffff',
'main': '#f2f2f3',
'content': '#ffffff'
}),
textColor: theme => ({
...theme('colors'),
'main': '#333333'
})
},
plugins: [require('#tailwindcss/forms'), require('#tailwindcss/typography')],
}
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")])
.sass('resources/sass/app.scss', 'public/css')
.sourceMaps();
resources/css/app.css
#import 'tailwindcss/base';
#import 'tailwindcss/components';
#import 'tailwindcss/utilities';
Solved this pseudo issue.
The problem was that I didn't quite understand the new thing about changing purge to content and that now I have to compile the styles whenever I change them. Also, the previous version of phpstorm didn't see the classes and didn't give hints because of this.

rollup postcss plugin doesn't seem to work with scss and CSS Modules

The symptom
When are run rollup -c I get a reasonable build, but I get this error if I use the SCSS double slash comments:
CssSyntaxError: //../packages/core/src/styles/layout.module.scss:56:8: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
As far as I can tell, I have setup the plugin to use sass and to use CSS Modules. When I try to set the parser to "postcss-scss" I get this other error:
[!] (plugin postcss) TypeError: node.getIterator is not a function
rollup.config.js
import url from "#rollup/plugin-url";
import svgr from "#svgr/rollup";
import autoprefixer from "autoprefixer";
import { resolve } from "path";
import postcssNormalize from "postcss-normalize";
import babel from "rollup-plugin-babel";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import { nodeResolve } from "#rollup/plugin-node-resolve";
import commonjs from "#rollup/plugin-commonjs";
import typescript from "#rollup/plugin-typescript";
import packageJson from "./package.json";
export default [
{
input: "src/components/index.ts",
output: [
{
file: `${packageJson.main}`,
format: "cjs",
sourcemap: true,
},
{
file: `${packageJson.module}`,
format: "esm",
sourcemap: true,
},
],
plugins: [
// include peer deps in the package
peerDepsExternal(),
// The next 2 allow importing commonjs packages like classnames
commonjs(),
nodeResolve(),
// transform
babel({
exclude: "node_modules/**",
}),
typescript({
typescript: require("typescript"),
tsconfig: "./tsconfig-prod.json",
}),
postcss({
plugins: [autoprefixer(), postcssNormalize()],
// exclude: "src/styles/**/*.scss",
namedExports: true,
sourceMap: true,
extract: false,
// modules: true,
autoModules: true,
minimize: true,
extensions: [".scss"],
use: ["sass"],
// parser: "postcss-scss",
}),
url(),
svgr(),
],
},
};
There are a couple of commented out options, which I have also tried. Yes, I can switch comment type - the sheer number of files notwithstanding, but it bothers me that this setup is not quite working, so any help would be much appreciated.
In the src/components folders I have this folder strcuture pattern for each component:
components ->
> Button ->
> index.ts
> Button.tsx
> Button.module.scss

How Do I Override Tailwind Base With SASS/SCSS

My Issue
My h3 font-weight override doesn't appear to work.
#tailwind base;
h3{
#apply font-thin;
}
#tailwind components;
#tailwind utilities;
h3{
#apply font-thin;
}
As you can see in the image, the layout.css coming from Tailwind takes precedence over my styles.scss
Some more background:
Gatsby project with PostCSS and SASS plugin (I've copied the relevant gatsby-config.js here:
module.exports = {
plugins: [
`gatsby-plugin-postcss`,
{
resolve: `gatsby-plugin-sass`,
options: {
postCssPlugins: [
require("tailwindcss"),
require("./tailwind.config.js"), // Optional: Load custom Tailwind CSS configuration
],
}
},
],
}
Oh I figured out the issue, layout.css isn't from Tailwinds ... it's boilerplate from Gatsby starter theme.
Found it and removed it from src/components/layout.js

Issue with with custom webpack configuration

Laravel Mix (4.0.15)
OS Ubuntu 18.04
Steps to Reproduce:
Create a New laravel project (Laravel 5.8, as it uses laravel-mix 4)
Import a component dynamically.
Vue.component('example', () => import('./components/Example.vue'));
I have been using babel dynamic import to import this.
"#babel/plugin-syntax-dynamic-import": "^7.2.0",
You may need .babelrc in the root.
try to put the chunks file into public/js/prod It works file till now.
let mix = require('laravel-mix');
mix.webpackConfig({
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
// 'vue$': 'vue/dist/vue.esm.js',
'#': __dirname + '/resources/assets/js'
},
},
output: {
chunkFilename: 'js/prod/[name].js',
},
});
mix.js('resources/assets/js/app.js', 'js')
.version();
try to extract the plugins, & It causes problem.
mix.js('resources/assets/js/app.js', 'js')
.mix.extract(['vue','jquery', 'popper.js'])
.version();
Now the file app.js and vendor.js goes to js/prod//js/app.js and js/prod//js/vendor.js respectively.
There is no way to put the app.js and vendor.js in /js and chunks in /js/prod. In the previous version which was available.

Resources