How to lint SASS/SCSS on Laravel Mix - laravel-mix

I have failed to find a solution for this. The only possible outcome I've seen so far is Laravel-Elixir-SCSS-Lint but the current download numbers doesn't indicate me this is the general choice of the public. I did look into the Laravel Mix Extensions page, nothing obvious there either. Never thought there was not going to be a clear option for Laravel Mix having lint SASS/SCSS before with Gulp, Grunt, etc.
Thank you in advance for the help.
Update
After much digging I have come to the following solution, however the linting is not doing a good job and several mistakes are ignored (check console output at the end)
package.json
{
"name": "test",
"version": "1.0.0",
"description": "Description here.",
"main": "index.js",
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "cross-env NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Me",
"license": "ISC",
"devDependencies": {
"aos": "^2.3.4",
"browser-sync": "^2.26.4",
"browser-sync-webpack-plugin": "^2.0.1",
"cross-env": "^5.2.0",
"laravel-mix": "^4.0.15",
"postcss-reporter": "^6.0.1",
"resolve-url-loader": "^3.1.0",
"sass": "^1.19.0",
"sass-loader": "^7.1.0",
"stylelint": "^10.0.1",
"stylelint-config-recommended": "^2.2.0",
"stylelint-order": "^3.0.0",
"stylelint-scss": "^3.6.0",
"vue-template-compiler": "^2.6.10"
}
}
webpack.mix.js
let mix = require('laravel-mix');
if (!mix.inProduction()) {
mix.webpackConfig({
devtool: 'source-map'
})
.sourceMaps()
}
mix
.copy('libraries/jquery-vide/jquery.vide.min.js', 'dist/js/')
.copy('libraries/headroom/headroom.js', 'dist/js/')
.js('src/js/ab2019.js', 'dist/js/')
.js('src/js/ab2019-vide.js', 'dist/js/')
.sass('src/sass/style.scss', 'dist/css/')
.options({
processCssUrls: false, // Process/optimize relative stylesheet url()'s. Set to false, if you don't want them touched.
postCss:[
require("stylelint")({ /* your options */ }),
require("postcss-reporter")({ clearReportedMessages: true })
]
})
.browserSync({
files: "dist/css/style.css"
})
.setPublicPath('dist');
.stylelintrc.json
{
"extends": "stylelint-config-recommended",
"plugins": [
"stylelint-order",
"stylelint-scss"
],
"rules": {
"block-no-empty": true,
"declaration-colon-space-after": "always",
"indentation": [ 2, {
"message": "Please use 2 spaces for indentation. Tabs make The Architect grumpy.",
"severity": "warning"
} ],
"no-descending-specificity": null,
"order/order": [
"declarations"
],
"order/properties-alphabetical-order": true,
"scss/dollar-variable-colon-space-after": "always-single-line"
}
}
style.scss
$x:1;
.test {
color: white;
background: red
}
.foo {}
a {
}
.bar {
color:#4fd;
padding: 10px 0px;
}
console output
$ npm run dev
> test#1.0.0 dev /fake/path
> npm run development
> test#1.0.0 development /fake/path
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
40% building 7/8 modules 1 active ...e/fake/path/src/sass/style.scss
src/sass/style.scss
32:2 ⚠ Expected background to come before color (order/properties-alphabetical-order) [stylelint]
70% building 9/10 modules 1 active ...e/fake/path/src/sass/style.scss
src/sass/style.scss
32:2 ⚠ Expected background to come before color (order/properties-alphabetical-order) [stylelint]
98% after emitting SizeLimitsPlugin
DONE Compiled successfully in 1489ms

If anyone has this problem I managed to make it work like this.
First I installed:
npm install stylelint stylelint-webpack-plugin --save-dev
Then I added this configuration inside webpack.mix.js file
const StylelintPlugin = require('stylelint-webpack-plugin');
mix.webpackConfig({
...
plugins: [
new StylelintPlugin({ // put your config here
configFile: '.stylelintrc', // path to config file
failOnError: false // don't fail on error
})
]
});
Peace

Related

Error when compiling in production mode "is not a function" Vue Laravel Mix

I have a Laravel, VueJs, VueRouter, Vuex application using Webpack to compile my assets.
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"#fortawesome/fontawesome-free": "^5.14.0",
"axios": "^0.18",
"bootstrap": "^4.0.0",
"laravel-mix": "^3.0.0",
"lodash": "^4.17.19",
"popper.js": "^1.12",
"vue": "^2.5.7"
},
"dependencies": {
"#fullcalendar/core": "^5.11.3",
"#fullcalendar/daygrid": "^5.11.3",
"#fullcalendar/interaction": "^5.11.3",
"#fullcalendar/list": "^5.11.3",
"#fullcalendar/timegrid": "^5.11.3",
"#fullcalendar/vue": "^5.11.3",
"ajv": "^6.12.3",
"animate.css": "^3.7.2",
"aos": "^2.3.4",
"apexcharts": "^3.33.0",
"chart.js": "^2.7.3",
"element-ui": "^2.4.8",
"imagemin": "^6.0.0",
"jquery": "^3.4.1",
"moment": "^2.27.0",
"node-sass": "^4.14.1",
"numeral": "^2.0.6",
"simple-keyboard": "^2.29.72",
"toastr": "^2.1.4",
"vue-apexcharts": "^1.6.2",
"vue-chartjs": "^3.4.0",
"vue-data-tables": "^3.4.5",
"vue-router": "^3.5.2",
"vue-touch-keyboard": "^0.3.2",
"vuedraggable": "^2.24.3",
"vuex": "^3.5.1",
"xml-js": "^1.6.11"
}
}
when i build in production mode npm run prod i get the error s is not a function
but if i build in dev like npm run watch or npm run dev i don't get the error.
How can I debug where the error is in the code so I can fix it? It only shows me in the vue.common.prod line.
vue.common.prod.js:11 TypeError: s is not a function
at e (vue.common.prod.js:11:68600)
my file 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 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/front/app.js', 'public/js')
.extract(['vue','vuex', 'jquery', 'bootstrap', 'axios', 'element-ui', 'lodash', 'moment', 'popper.js'])
.version();
mix.webpackConfig({
resolve: {
extensions: ['.js', '.json', '.vue'],
alias: {
'#': path.join(__dirname, './resources/js'),
'~': path.join(__dirname, './resources/js/front'),
'##': path.join(__dirname, './modules'),
'#components': path.join(__dirname, './resources/js/components')
}
},
output: {
filename:'[name].js',
chunkFilename: 'js/[name].js',
},
}).sourceMaps()
option 01) :
check the function you wrote
This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute s function that is not initialized or is not initialized correctly. This means that the expression did not return s function object. So you need to understand that what you are trying to achieve is not s feature.
option 02) :
remove node_module and clear cache npm cache clear --force.
after that reinstall node_module by using npm install.
option 03) :
check your imported thing forgot the curly braces in an import statement.

New to npm get SyntaxError: Unexpected token

Edit : I've change my package.json according to the progress of my research it seems to be related to babel, I keep looking. However, I wanted to change the package.json that I present to you from which I will work from now on and try to find the right dependencies.
I am currently facing a problem to integrate the coreui template into laravel 5.7.
I get this error :
Module build failed: SyntaxError: Unexpected token.
It happened in the router file. It crashes at the component import level.
import Vue from 'vue'
import Router from 'vue-router'
// Containers
const DefaultContainer = () =>/* HERE */ import('#/containers/DefaultContainer')
I am new to npm and really don't know how to solve that. So any help will be highly appreciated.
Here is my package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.18",
"cross-env": "^5.1",
"install": "^0.12.1",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.5",
"popper.js": "^1.12",
"vue": "^2.5.7"
},
"dependencies": {
"#coreui/coreui": "^2.0.4",
"#coreui/icons": "^0.3.0",
"#coreui/vue": "^2.0.0",
"bootstrap-vue": "^2.0.0-rc.11",
"flag-icon-css": "^3.2.0",
"font-awesome": "^4.7.0",
"perfect-scrollbar": "^1.4.0",
"simple-line-icons": "^2.4.1",
"vue-router": "^3.0.1"
}
}
To solve this problem I just create a file .babelrc on the root of the project and add
{
"plugins": ["#babel/plugin-syntax-dynamic-import"]
}
Now I get an other issue that I ask in other question.
Thank you Boussadjra Brahim for your help :)

Laravel + IE + Axios = "Promise is undefined."

I have the following code for running AJAX requests in Laravel using Axios:
axios.post('Ajax/upload',{key:this.key})
.then(function(response)
{
console.log(response);
}).catch(function(response) {
console.log(response)
});
It works fine in Chrome, but in Internet Explorer I only get the following error:
Promise is udefined.
In the app.js file the breakpoint is set on:
var chain = [dispatchRequest, undefined];
var promise = Promise.resolve(config);
I have the following packages in the package.json file:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "0.18",
"bootstrap": "4.0.0",
"cross-env": "^5.1",
"jquery": "3.3.1",
"laravel-mix": "^1.0",
"noty": "3.1.4",
"pace-js": "1.0.2",
"vue": "^2.5.7"
},
"dependencies": {
"popper.js": "^1.14.4"
}
}
Are there any packages I need to add in order to make Axios work in Internet Explorer? Or are there any other workarounds?
Thanks for any help!
IE doesn't support promises out of the box, you'll need a polyfill. There are several to choose from. MDN's promise page links to this one. Axios' own documentation links to this one.

Laravel mix doesn't compile file as expected

I have an issue with mix that I can't seem to fix.
I have a file in which I require several node modules and init a vue root component
routes.js
window.Vue = require('vue');
window._ = require('lodash');
window.axios = require('axios');
const root = new Vue({
el: '#root'
});
In my mix file I define where the file should be compiled like so:
mix.js('resources/assets/js/routes.js', 'public/assets/js');
Everything compiles without any errors using npm run dev but when I open the compiled file the contents are not compiled at all! It's like the file wasn't run trough webpack and just copied.
The weird thing is that I use several other components on different pages that do compile like they should. I'm at a loss what the problem might be for this specific instance, since the way the file is built up and the mix directive in webpack.mix.js is exactly the same.
Any help is greatly appreciated!
Edit: package.json contents.
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"autoprefixer": "^8.0.0",
"axios": "^0.17",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"node-sass": "^4.7.2",
"vue": "^2.5.7"
},
"dependencies": {
"awe-dnd": "^0.3.0",
"slick-carousel": "^1.8.1",
"tinymce": "^4.7.6",
"vue-l-carousel": "^1.0.1"
}
}

Webpack can't find (font) dependencies

NPM/Webpack can't find dependencies with Laravel Mix
These dependencies were not found:
* font-awesome
* ionicons
ERROR in multi lodash jquery bootstrap-sass fastclick jquery-slimscroll admin-lte icheck ionicons font-awesome datatables.net datatables.net-bs
Module not found: Error: Can't resolve 'font-awesome' in 'D:\Laragon'
# multi lodash jquery bootstrap-sass fastclick jquery-slimscroll admin-lte icheck ionicons font-awesome datatables.net datatables.net-bs
More clearly. These are installed (can find them in node_modules) and require location is correct. I'm also using more packages, and these problems are related to, coincidentally, the only fonts in my webpack.
They are available in the package.json and package.json.lock.
Installed trying different methods: firstly npm install and --save-dev, also tried yarn install and yarn add.
My webpack.mix.js:
let 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.webpackConfig({
module: {
loaders: [
{
test: /\.js?/,
exclude: [/node_modules/, /styles/],
loaders: ['babel'],
include: path.join(__dirname, 'src')
},
{
test: /\.scss$/,
loader: 'style!css!resolve-url!sass?sourceMap'
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}
]
}
});
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
mix.js('resources/assets/js/auth.js', 'public/js')
.sass('resources/assets/sass/auth.scss', 'public/css');
mix.js('resources/assets/js/admin-lte.js', 'public/js')
.sass('resources/assets/sass/admin-lte.scss', 'public/css');
mix.autoload({
jquery: [ '$', 'jQuery', 'jquery'],
DataTable: 'datatables.net-bs'
});
mix.extract([
'lodash', 'jquery', 'bootstrap-sass',
'fastclick', 'jquery-slimscroll', 'admin-lte',
'icheck', 'ionicons', 'font-awesome',
'datatables.net', 'datatables.net-bs'
], 'public/js/vendor.js');
mix.version();
I also tried it without the mix.webpackConfig, adding the config this was a desperate attempt to fix the fonts.
Here is my package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"admin-lte": "^2.4.2",
"axios": "^0.17",
"bootstrap": "^4.0.0",
"cross-env": "^5.1.3",
"datatables.net": "^1.10.16",
"fastclick": "^1.0.6",
"font-awesome": "^4.7.0",
"icheck": "^1.0.2",
"ionicons": "^3.0.0",
"jquery": "^3.3.1",
"jquery-slimscroll": "^1.3.8",
"laravel-mix": "^2.0",
"lodash": "^4.17.4",
"popper.js": "^1.12",
"script-loader": "^0.7.2"
},
"dependencies": {
"bootstrap-sass": "^3.3.7",
"datatables.net-bs": "^1.10.16"
}
}
And in my .scss:
#import '~font-awesome/scss/font-awesome';
Both on Mac and Windows 10
Include Font Awesome into your NPM config
"devDependencies": {
......
......
"font-awesome": "^4.7.0"
}
Run npm update
And then your app.scss include this
// Font Awesome
#import "~font-awesome/scss/font-awesome.scss";
Run npm dev or `npm watch
Getting rid of font-awesome and ionicons from the extract function solves the problem.

Resources