Search code examples
laravelmaterial-components-web

How to configure material components web with laravel-mix?


I use mdc with laravel-mix but it's not loading scss files from node modules. I tried some other solutions about giving includepaths in mix.sass, but they are not working.

I tried code in webpack.mix.js

const path = require('path');
let mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css', {
    includePaths:  ['./node_modules']
});

but its still giving me same error that

 undefined
        ^
       Can't find stylesheet to import. @import "@material/elevation/mixins";

Solution

  • For Laravel 6 I had to do it this way:

    npm install --save material-components-web

    app.scss: @import "material-components-web/material-components-web";

    webpack.mix.js:

    mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css', {
        sassOptions: {
            includePaths:  ['./node_modules']
        }
    });