Laravel Mix 6.0.25 not building with #tailwindcss/jit - laravel

I'm trying to replace the Tailwindcss compiler with #tailwindcss/jit in a Laravel project that is using Vue Laravel Mix but I'm getting this Unknown word error.
✖ Mix Compiled with some errors in 489.07ms
ERROR in ./resources/sass/app.scss Module build failed (from
./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from
./node_modules/postcss-loader/dist/cjs.js): SyntaxError
(1:1) /Users/username-76/Desktop/projectname/resources/sass/app.scss
Unknown word
1 | import api from "!../../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
| ^ 2 | import content from "!!../../node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[6].oneOf[1].use[1]!../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[6].oneOf[1].use[2]!../../node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[6].oneOf[1].use[3]!./app.scss";
3 |
at processResult (/Users/username-76/Desktop/projectname/node_modules/webpack/lib/NormalModule.js:701:19)
at /Users/username-76/Desktop/projectname/node_modules/webpack/lib/NormalModule.js:807:5
at /Users/username-76/Desktop/projectname/node_modules/loader-runner/lib/LoaderRunner.js:399:11
at /Users/username-76/Desktop/projectname/node_modules/loader-runner/lib/LoaderRunner.js:251:18
at context.callback (/Users/username-76/Desktop/projectname/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
at Object.loader (/Users/username-76/Desktop/projectname/node_modules/postcss-loader/dist/index.js:140:7)
1 ERROR in child compilations (Use 'stats.children: true' resp.
'--stats-children' for more details) webpack compiled with 2 errors
app.scss
/* purgecss start ignore */
#tailwind base;
#tailwind components;
/* purgecss end ignore */
#tailwind utilities;
html, body {
#apply font-sans;
#apply text-darkblue;
}
webpack.mix.js
const mix = require('laravel-mix');
mix.disableSuccessNotifications();
mix.js('resources/js/app.js', 'public/js').vue();
mix.postCss("resources/sass/app.scss", "public/css", [
require("#tailwindcss/jit"),
]);
mix.version();

You're using the PostCSS plugin, yet you are attempting to compile SASS. Do it the following way instead.
.postCss('resources/css/app.css', 'public/css', [
require('tailwindcss')
])
.options({
postCss: [ tailwindcss('./tailwind.config.js') ],
})
Your app.css would include Tailwind:
#import 'tailwindcss/base';
#import 'tailwindcss/components';
#import 'tailwindcss/utilities';
And then in your tailwind.config.js would include the just-in-time mode.
module.exports = {
mode: 'jit',
/* These paths are just examples, customize
them to match your project structure
*/
purge: [
'./storage/framework/views/*.php',
'./resources/**/*.blade.php',
'./resources/**/*.js',
'./resources/**/*.vue',
],
theme: {
}
}

Related

Blank Page on production using Laravel Mix

I built a single page application (SPA) using Laravel 8 + Vue.js + InertiaJs. Everything is working fine in the development environment, but when I compile assets for production, it shows me a blank page, and there is no error in the console. All assets are loading correctly with a 200 code, and everything seems to be OK, but the Vue app is not mounting!
webpack.mix.js
const mix = require('laravel-mix');
require('laravel-mix-workbox');
mix.webpackConfig({
output: {
filename: '[name].js',
chunkFilename: 'js/[name].js',
}
}).js('resources/js/app.js', 'public/js')
.extract(['vue'])
.version();
Image1
Image2
Image3
try using the inertiajs webpack.mix.js provided by the pingCRM github:
const path = require('path')
const mix = require('laravel-mix')
const cssImport = require('postcss-import')
const cssNesting = require('postcss-nesting')
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix
.js('resources/js/app.js', 'public/js')
.vue()
.postCss('resources/css/app.css', 'public/css', [
// prettier-ignore
cssImport(),
cssNesting(),
require('tailwindcss'),
])
.webpackConfig({
output: { chunkFilename: 'js/[name].js?id=[chunkhash]' },
resolve: {
alias: {
vue$: 'vue/dist/vue.runtime.esm.js',
'#': path.resolve('resources/js'),
},
},
})
.version()
.sourceMaps()
note you may have to follow the instructions for setting up tailwindcss which can be found here, only do this if you plan to use it otherwise remove the require('tailwindcss'), from the webpack file
you also may need to npm install --save-dev postcss-import and npm install --save-dev postcss-nesting the --save-dev flag will add it to your package.json file for future reference

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

How to resolve aliases in mocha-webpack for laravel vue single file components

I am using vuejs in Laravel 5.7 to build an SPA. I am using mocha-webpack and vue-test-utils to write some vue component tests.
The tests can't seem to work out stylesheet imports into components. For example: I have a ExampleComponent.vue which includes the following:
</script>
<style lang="scss" scoped>
#import '#/_variables.scss';
.subpanel-control > ul > li {
background-color: lighten($body-bg, 50);
margin-left: 10px;
height: 25px;
width: 25px;
line-height: 25px;
color: $body-bg;
}
when running npm run test I get the following error:
Error in ./resources/assets/js/components/Panel.vue?vue&type=style&index=0&id=21f01f46&lang=scss&scoped=true&
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
#import '#/variables';
^
Can't find stylesheet to import.
╷
98 │ #import '#/variables';
│ ^^^^^^^^^^^^^
╵
stdin 98:9 root stylesheet
in C:\Users\jjackson\Documents\projects\wave\resources\assets\js\components\Panel.vue (line 98, column 9)
I can't work out why it doesn't understand the alias #. Here is my webpack.mix.js:
let mix = require('laravel-mix');
const path = require('path');
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.sass('resources/assets/sass/nifty.scss', 'public/css', {
implementation: require('node-sass')
})
.sass('resources/assets/sass/themes/type-b/theme-ocean.scss', 'public/css')
.less('resources/assets/less/bootstrap-4-utilities.less', 'public/css')
.webpackConfig({
resolve: {
alias: {
'#': path.resolve('resources/assets/sass'),
'~': path.resolve('resources/assets/js')
}
}
})
.sourceMaps();
if (mix.inProduction()) {
mix.version();
}
Any help would be appreciated
While struggling with the same issue I landed on this page - https://github.com/vuejs/vue-cli/issues/4053 and a comment from robbishop that lead me to my solution.
Using the above I managed to find a configuration in webpack.mix.js that seem to work:
First install null-loader (npm i -D null-loader)
Add the following line in rules:
{ test: /\.scss$/, use: [{ loader: 'null-loader' }] }
My webpack.mix.js looks like that:
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.webpackConfig({
module: {
rules: [
{ test: /\.scss$/, use: [{ loader: 'null-loader' }] }
]
},
resolve: {
alias: {
'#': path.resolve('somepath/sass')
}
}
})
.sass('some/path/app.scss', 'some/path/css');
My unit tests are now executed while having scss imports in my components.
This turned out to be a docker problem. Was trying to run npm run dev outside of the docker environment, and it was causing this error. When I ran all npm commands inside of the container everything worked fine

#apply` cannot be used with `.bg-blue` because `.bg-blue` either cannot be found, or its actual definition includes a pseudo-selector

I'm trying to use #apply in my sass file, and getting the error in the title when I do npm run dev or npm run watch. I'm using Laravel, and using Laravel Mix. Here is my webpack.mix.js
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.options({
processCssUrls: false,
postCss: [ tailwindcss('./tailwind.config.js') ],
});
This exists in my app.css
...
.bg-blue {
background-color: #47cdff;
}
My app.scss:
// Tailwind CSS
#tailwind base;
#tailwind components;
#tailwind utilities;
// Custom CSS
.section {
#apply .px-4;
}
.button {
#apply .bg-blue .text-white .no-underline .rounded-lg .text-sm .py-2 .px-5;
box-shadow: 0 2px 7px 0 #b0eaff;
}
Just override the default color pallete, you can do so using the theme.colors section of your tailwind.config.js file :
theme: {
colors: {
white: '#FFFFFF',
blue: '#007ace',
}
}
Then an easy trick never mix regular CSS and imports in the same file. Instead, create one main entry-point file for your imports, and keep all of your actual CSS in separate files.

"xxx.scss" is not in the SourceMap error in Laravel Mix

I'm following Laravel documentation and have this file structure:
In app.scss I have:
#import 'style12';
.real-demo{
}
and in style12.scss some css code which i try to import.
When I run npm run dev I get following error:
Module build failed: Error: "../../resources/assets/sass/style12.scss" is not in the SourceMap.
at BasicSourceMapConsumer.SourceMapConsumer_sourceContentFor [as sourceContentFor] (C:\Users\mixei\Desktop\Projects\westcredit\node_modules\source-map\lib\source-map-consumer.js:704:13)
at SourceMapGenerator.<anonymous> (C:\Users\mixei\Desktop\Projects\westcredit\node_modules\source-map\lib\source-map-generator.js:235:40)
at Array.forEach (<anonymous>)
at SourceMapGenerator_applySourceMap [as applySourceMap] (C:\Users\mixei\Desktop\Projects\westcredit\node_modules\source-map\lib\source-map-generator.js:234:32)
at MapGenerator.applyPrevMaps (C:\Users\mixei\Desktop\Projects\westcredit\node_modules\postcss\lib\map-generator.js:146:22)
at MapGenerator.generateMap (C:\Users\mixei\Desktop\Projects\westcredit\node_modules\postcss\lib\map-generator.js:194:46)
at MapGenerator.generate (C:\Users\mixei\Desktop\Projects\westcredit\node_modules\postcss\lib\map-generator.js:297:25)
at LazyResult.stringify (C:\Users\mixei\Desktop\Projects\westcredit\node_modules\postcss\lib\lazy-result.js:294:24)
at C:\Users\mixei\Desktop\Projects\westcredit\node_modules\postcss\lib\lazy-result.js:231:27
Also here is my webpack.mix.js:
const { mix } = require('laravel-mix');
mix.options({
processCssUrls: false
});
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
Any help will be appreciated, thanks!

Resources