Use Material Design Components with ember-cli-sass

拥有回忆 提交于 2019-12-24 07:06:53

问题


I'm trying to use Material Components Web(MDC-Web) sass functionality with ember-cli-sass. I've installed MDC-Web with Yarn

In my ember-cli-build.js file I've set my sass includePaths as so:

 sassOptions: {
           includePaths: ['node_modules/material-components-web','node_modules/@material']      
    }

and then in my app.scss file attempted to import the full component library like so:

@import "material-components-web";

However I'm getting the error:

Error: Error: File to import not found or unreadable: @material/button/mdc-button.

Why is the SASS compiler not finding it?


回答1:


This issue got me as well the first time I was starting out. I've been using it in my ember app for a few months now and this is what works for me in my app.scss

// Parent MDC Theming example

$mdc-theme-primary: #009688;
$mdc-theme-secondary: #00bcd4;
$mdc-theme-background: #fff;

@import "material-components-web/material-components-web";

// Overrides to follow example

.mdc-grid-tile__secondary{
    background-color: rgba(0, 150, 136, 0.75);
}
.mdc-list-item{
    white-space: unset;
    overflow: visible;
}

And in ember-cli-build

sassOptions: {
  includePaths: [
    'node_modules'
  ]
}



回答2:


In ember you have to import dependencies, that are not ember addons, in ember-cli.build.js. See https://guides.emberjs.com/v2.18.0/addons-and-dependencies/managing-dependencies. Since 2.15 it is also possible to import from node_modules (https://discuss.emberjs.com/t/import-javascripts-from-node-modules-packages/13606).

But in case of material-components-web this shouldn't be necessary at all. Instead you can simply use the ember addon ember-material-components-web that includes material-components-web for you.



来源:https://stackoverflow.com/questions/48083865/use-material-design-components-with-ember-cli-sass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!