material-components-web icon indicating copy to clipboard operation
material-components-web copied to clipboard

How do we set the @material Sass folder include path scope ???

Open jmbrnrd opened this issue 9 years ago • 12 comments

In this section: https://github.com/material-components/material-components-web#css there is a NOTE: "The components' Sass files expect that the node_modules directory containing the @material scope folder is present on the Sass include path." How is this done now in an Angular CLI project?

jmbrnrd avatar Mar 09 '17 21:03 jmbrnrd

For my webpack setup personally, It was impossible to get @material working.

Here's what I had to do. Just import it all at one. :|

@import '~material-components-web/material-components-web';

And it depends on your build process. Webpack? Grunt? Gulp?

kminehart avatar Mar 14 '17 15:03 kminehart

My build process is Webpack, but there's no access to the config as I'm using the AngularCli. I did originally try what you suggested but I got a bunch of other errors as there are also inter-package dependency which fail for the same reasons. :(

jmbrnrd avatar Mar 14 '17 16:03 jmbrnrd

Not sure what to tell you if you don't have access to the webpack config. I added it to my sass include path like so: (webpack 2)

{
  test: /\.(sass|scss)$/,
  use: [
    'style-loader',
    'css-loader',
    {
      loader: 'sass-loader',
      options: {
        includePaths: [
          'node_modules', 'bower_components', 'src', '.'
        ]
      },
    },
  ]
},

kminehart avatar Mar 14 '17 17:03 kminehart

Hello,

In your .angular-cli.json you should add:

 "apps": {
    ...
    "stylePreprocessorOptions": {
        "includePaths": [
          "../node_modules"
        ]
      },
    ...
  }

pierre-hilt avatar Mar 14 '17 20:03 pierre-hilt

Thank you @pierre-hilt simple if you know how! If only that were documented somewhere...

jmbrnrd avatar Mar 15 '17 09:03 jmbrnrd

For anyone working with Grunt and Grunt-Sass.

sass: {
            options: {
                sourceMap: true,
                relativeAssets: false,
                outputStyle: 'compressed',
                sassDir: 'css',
                cssDir: 'css',
                includePaths: [
                  'node_modules/'
                ]
            },
            build: {
                files: [{
                    expand: true,
                    cwd: 'css/',
                    src: ['**/*.{scss,sass}'],
                    dest: 'css',
                    ext: '.min.css'
                }]
            }
        },

RhysyG avatar May 16 '17 07:05 RhysyG

And for Gulp? I am using Web Starter Kit and facing same issue.

gauravmak avatar May 25 '17 13:05 gauravmak

@kminehart thank you so much!

milebza avatar Oct 02 '17 15:10 milebza

Any updates for Gulp?

aaidenduaban avatar Nov 17 '17 18:11 aaidenduaban

This is what worked in my setup;

  • ./node_modules/material-components-web/node_modules
...
gulp.task('styles', function(){
    gulp.src(sassFiles)
    .pipe(sass({includePaths: ['./node_modules/material-components-web/node_modules'], outputStyle: 'compressed'}).on('error', sass.logError))
    .pipe(gulp.dest(cssDest));
});
...

bery avatar Nov 25 '17 15:11 bery

For Gulp see this link it works fine for me : https://github.com/material-components/material-components-web/issues/603#issuecomment-315523198

valerieblanchard avatar Nov 07 '18 08:11 valerieblanchard

@pierre-hilt works like charm

sreenivasarajiv avatar Jun 28 '19 05:06 sreenivasarajiv