Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing SASS partials from node_modules

Tags:

sass

gulp

Trying to build custom workflow with gulp, panini, mustache, sass and one of my problem is including partials from node_modules, here is example from main.scss file:

@import "node_modules/bootstrap/scss/mixins";
@import "settings";

How to avoid typing full path to _mixins.scss?

like image 533
RomkaLTU Avatar asked Jan 14 '17 08:01

RomkaLTU


2 Answers

You can include node_modules in sass pathes:

.pipe(sass({
  includePaths: ['node_modules']
})

Then you can import library's sass like this:

@import "bootstrap/scss/bootstrap";

Or, in case of material-components-web:

@import "@material/top-app-bar/mdc-top-app-bar";

This way:

  • you don't need to add each lib to path
  • the sub-dependencies imports will work seamlessly, e.g. mdc-top-app-bar in MDC example imports "@material/elevation/mixins".
like image 131
Artem Vasiliev Avatar answered Sep 19 '22 22:09

Artem Vasiliev


Your question is similar to this: Sass import not crawling node_modules to find appropriate package

You can include paths by passing the includePaths argument to gulp sass. e.g

.pipe($.sass({
  includePaths: ['node_modules/bootstrap/scss/', 'another/path']
})
like image 37
Davey Avatar answered Sep 18 '22 22:09

Davey