Laravel mix compiling vuetify styles.sass to empty css file - laravel

I'm trying to compile vuetify 2.0.0-beta.9 SASS using laravel mix. The output of the styles.sass is an empty css file. How can I fix this?
As per the documentation (), First I ran:
$ npm install sass sass-loader fibers deepmerge --dev
Then created a main.scss file in resources/sass. Which contains the following:
#import '~vuetify/src/styles/main.sass';
#import '~vuetify/src/styles/styles.sass';
$body-font-family: 'Amiri', serif;
This produces a css file that seems incomplete because the styling of the site goes crazy while works fine if I just link a CDN or import a compiled one from ~vuetify/dist/vuetify.css
I need to compile it myself rather than just importing from ~vuetify/dist/vuetify.css because I want to change the $body-font-family variable.
To test, I first commented the styles.sass,
#import '~vuetify/src/styles/main.sass';
//#import '~vuetify/src/styles/styles.sass';
//$body-font-family: 'Amiri', serif;
This confirmed that main.sass is being compiled. So next, I tried:
//#import '~vuetify/src/styles/main.sass';
#import '~vuetify/src/styles/styles.sass';
//$body-font-family: 'Amiri', serif;
Which output a file with only the following:
/** Ripples */
/** Elements */

SOLVED: davejm's sample project using vuetify-loader solved it for me! Thanks!
github.com/nekosaur/laravel-vuetify

After many issues, I solve this on Laravel 8.
// Dependencies
{
"laravel-mix": "^6.0.6",
"sass": "^1.20.1",
"sass-loader": "^8.0.0",
"vue": "^2.5.17",
"vue-loader": "^15.9.5",
"vue-template-compiler": "^2.6.10",
"vuetify": "^2.4.3",
"vuetify-loader": "^1.7.1",
}
// webpack.mix.js
const mix = require('laravel-mix');
const webpack = require('./webpack.config');
Mix.listen('configReady', webpackConfig => {
// scss
const scssRule = webpackConfig.module.rules.find(
rule =>
String(rule.test) ===
String(/\.scss$/)
);
scssRule.oneOf.forEach(o => {
const scssOptions = o.use.find(l => l.loader === 'sass-loader').options
scssOptions.prependData = '#import "./resources/sass/_variables.scss";'
})
// sass
const sassRule = webpackConfig.module.rules.find(
rule =>
String(rule.test) ===
String(/\.sass$/)
);
sassRule.oneOf.forEach(o => {
const scssOptions = o.use.find(l => l.loader === 'sass-loader').options
scssOptions.prependData = '#import "./resources/sass/_variables.scss"'
})
})
mix.js('resources/js/app.js', 'public/js')
.js('resources/js/gift.js', 'public/js')
.vue()
.sass('resources/sass/pages/home.scss', 'public/css')
.sass('resources/sass/pages/gift.scss', 'public/css')
.webpackConfig(Object.assign(webpack))
.copyDirectory('resources/images/', 'public/images');
if (mix.inProduction()) {
mix.version();
};
// webpack.config.js
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
module.exports = {
plugins: [
new VuetifyLoaderPlugin(),
]
};

did you ever work this out? I'm in the same situation but Veutify is production version 2 (out of beta now).

This solution worked for me correctly, but you must have sass-loader 7, 8 is not compatible.

Related

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.

Laravel, Vue - "You may need an appropriate loader" for template tags

I am currently building a web application using Laravel and Vue. The error that I am getting is for all the components that I have.
ERROR in ./resources/assets/js/components/App 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
| <div id="layout-wrapper">
| <app-topbar></app-topbar>
# ./resources/assets/js/app.js 6:0-35 41:11-14
# multi ./resources/assets/js/app.js ./resources/assets/sass/style.scss
the App.vue file looks like this:
<template>
<div id="layout-wrapper">
<app-topbar></app-topbar>
<app-menu></app-menu>
<div class="main-content">
<div class="page-content">
<router-view></router-view>
<app-footer></app-footer>
</div>
</div>
</div>
</template>
<script>
import AppTopbar from './_partials/AppTopbar'
import AppMenu from './_partials/AppMenu'
import AppFooter from './_partials/AppFooter'
import Users from './users/Users'
import Dashboard from './dashboard/Dashboard'
export default {
components: {
'app-topbar': AppTopbar,
'app-menu': AppMenu,
'app-footer': AppFooter,
Users,
Dashboard,
},
beforeMount() {
axios.get('/metadata')
.then(response => {
window.Laravel = {
response: response,
current_year: response.current_year,
csrf: response.csrf,
asset(path){
return this.response.asset+'/'+path;
},
trans(text){
return this.response.trans[text];
},
route(name){
return this.response.base_url+'/'+this.response.routes[name];
}
};
});
},
}
</script>
From the error, I understand that the problem is that <template></template> tags are not being parsed. From what I found out I need the vue-loader and vue-template-compiler dependencies for them. I have already installed those, however, I still keep getting these errors.
I also found that trying the older version (current 15.x.x , older 14.x.x) of vue-loader could help, but it did not.
My versions are:
laravel 8.12.3
npm 6.14.4
package.json dependencies:
"devDependencies": {
"axios": "^0.19",
"cross-env": "^7.0",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.19",
"resolve-url-loader": "^3.1.0",
"sass": "^1.29.0",
"sass-loader": "^8.0.2",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"vue": "^2.6.12",
"vue-loader": "^14.2.4",
"vue-router": "^3.4.9"
}
Since I am not skilled in Vue, I understand that I did something wrong. However, I have not found solutions online. So, I would like to ask for your help.
Update:
Since Laravel has a pre-configured webpack.config file then probably, this is what I think I am able to show you.
webpack.mix.js :
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| 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.sass('resources/assets/sass/style.scss', 'public/assets')
.js('resources/assets/js/app.js', 'public/js')
.styles([
// Layout
'resources/assets/template/system/css/bootstrap.min.css',
'resources/assets/template/system/css/icons.min.css',
'resources/assets/template/system/css/app.min.css',
// Data Table
'resources/assets/template/system/css/dataTables.bootstrap4.min.css',
'resources/assets/template/system/css/responsive.bootstrap4.min.css',
// Custom
'public/assets/style.css'
], 'public/css/style.min.css')
.scripts([
// Layout
'resources/assets/template/system/js/jquery.min.js',
'resources/assets/template/system/js/bootstrap.bundle.min.js',
'resources/assets/template/system/js/metisMenu.min.js',
'resources/assets/template/system/js/simplebar.min.js',
'resources/assets/template/system/js/waves.min.js',
'resources/assets/template/system/js/jquery.sparkline.min.js',
'resources/assets/template/system/js/morris.min.js',
'resources/assets/template/system/js/raphael.min.js',
'resources/assets/template/system/js/app.js',
// Data Tables
'resources/assets/template/system/js/jquery.dataTables.min.js',
'resources/assets/template/system/js/dataTables.bootstrap4.min.js',
'resources/assets/template/system/js/dataTables.responsive.min.js',
'resources/assets/template/system/js/responsive.bootstrap4.min.js',
// Vue
//'resources/assets/template/system/js/vue.js',
// Custom
//'resources/assets/js/vue.js',
'public/js/app.js',
'resources/assets/js/script.js'
], 'public/js/script.min.js');
In Laravel 8 the compilation of assets works in a slightly different way. It will only add vue compilers as a dependency if you declare that you want to compile a vue file in webpack.mix.js.
See what happened to me after doing this: http://prntscr.com/whr7wv
Try changing
.js('resources/assets/js/app.js', 'public/js')
to
.js('resources/assets/js/app.js', 'public/js').vue()
and return to post if successful.
Note: consider not using laravel/ui and manually creating app.js
Application Laravel 8 + Vue 2.6 versions then please change the code in the
webpack.mix.js
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
]);
To
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
]).vue();
"you may need an appropriate loader to handle this file type" laravel and vue application error reason >> package.json - "laravel-mix": "^6.0.6" is version 6 or higher.
This is what worked for me (Laravel 8 + Vue 2.6). Change the code in the
webpack.mix.js
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sourceMaps();
to
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.vue();
then run
npm update vue-loader
Actually you have not installed ui for vue files in laravel, that's why it does not recognize the template tag in vue file. So run few commands in new terminal:
composer require laravel/ui
php artisan ui vue
npm install && npm run dev

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

Globally accessible sass variables in Laravel Mix

My goal is to get the following code working in .vue files in Laravel project:
<style scoped lang="scss">
#import 'variables'; // <-- file not found
// ...
</style>
Currently, whenever I try to run the above code, the "file not found" error is thrown by the sass compiler.
My current webpack.mix.js:
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.webpackConfig({
resolve: {
alias: {
tools: 'resources/assets/sass/tools' // <-- does not work
}
}
});
So the question is, how do I configure laravel-mix, so that I am able to include global sass files without having to use relative paths?
this worked for me :
const path = require('path')
function resolve (dir) {
return path.join(__dirname, dir)
}
resolve: {
alias: {
'blah': resolve('resources/assets/sass/blah')
}
}
#import '~blah/blah'
If you want a global variable, do not use scoped in the <style> tag

Gulp sass compilation issues

I'm facing an issue on Sass compilation with Gulp.
I've some variables defined in a file, _typos.scss, like this:
$AristaFont : "Arista", Trebuchet MS, sans-serif;
And when I use this variable in another file,_layout_header.scss, Gulp say the variable is not defined:
[gulp-sass] sass/layout/_layout-header.scssError: Undefined variable: "$AristaFont".
on line 107 of sass/layout/_layout-header.scss
These files are located in different folder like:
sass/layout/_layout-header.scss
sass/global/_typos.scss
Is it a problem for gulp-sass ? It wasn't with compass.
Thanks
EDIT: an excerpt of the application.scss witch import all scss files.
#import "global/_typos.scss";
#import "global/_style.scss";
#import "global/_flex.scss";
#import "global/_stacktable.scss";
/*#import "global/sub-nav";*/
// Import des partiels du layout du thème Drupal
#import "layout/_layout.scss";
#import "layout/_layout-nodes.scss";
#import "layout/_layout-nodes-flexbox.scss";
#import "layout/_layout-header.scss";
#import "layout/_layout-footer.scss";
My package.json excerpt:
"devDependencies": {
"event-stream": "^3.3.4",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-load-plugins": "^1.5.0",
"gulp-notify": "^3.0.0",
"gulp-sass": "^3.1.0",
"gulp-shell": "^0.6.3",
"gulp-size": "^2.1.0",
"gulp-sourcemaps": "^2.6.0",
"gulp-util": "^3.0.8",
"node-sass-import-once": "^1.2.0",
"notify-send": "^0.1.2",
"typey": "^1.1.1"
},
please use this way:
in gulpfile.js file use this code:
//////////////////////////////////////////
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
/**
--Top level function--
gulp.task = Define task
gulp.src = Point topfiles to use
gulp.dest = Points to folder to output
gulp.watch = watch files and folder for change
**/
//Log message
gulp.task('message', () =>
console.log("gulp is running... ")
);
//optimise images
gulp.task('imageMin', () =>
gulp.src("images/**/*")
.pipe(imagemin())
.pipe(gulp.dest("img_min"))
);
//compile sass
gulp.task('sass',() =>
gulp.src("sass/**/*.scss")
.pipe(sass().on('error',sass.logError))
.pipe(gulp.dest("css"))
);
//concatinate and minify js
gulp.task('script',()=>
gulp.src("js/**/*.js")
.pipe(concat("script.js"))
.pipe(uglify())
.pipe(gulp.dest("js"))
);
//all task in this file
gulp.task('default',['message', 'imageMin', 'sass', 'script']);
//watch command
gulp.task('watch', ['message', 'imageMin', 'sass', 'script'], function() {
gulp.watch("images/**/*",['imageMin']);
gulp.watch("sass/**/*.scss",['sass']);
gulp.watch("js/**/*.js",['script']);
});
/////////////////////////////////////////////////////
after that in your_main_sass_file.scss use this
#import "abstractions/**/*";
#import "variables/**/*";
#import "base/**/*";
#import "layout/**/*";
#import "components/**/*";
where abstraction,variables,base,layout,components are the folder inside the sass folder all of them contain different .scss partial files
and your_main_sass_file.scss is outside these folders;
hope this will work

Resources