简体   繁体   English

如何在 Sapper 项目中为 Svelte Material UI (SMUI) 组件使用自定义主题/颜色?

[英]How to use custom theme/colors for Svelte Material UI (SMUI) components in Sapper project?

I've followed the instructions for using Svelte Material UI (SMUI) in a Sapper project.我已按照在 Sapper 项目中使用 Svelte Material UI (SMUI)的说明进行操作。

I can import and use SMUI components with the default theme/colors if I leave src/theme/_smui-theme.scss blank.如果我将src/theme/_smui-theme.scss留空,我可以导入和使用具有默认主题/颜色的 SMUI 组件。 When I include the following code suggested by SMUI in this file to use custom colors, it tells me Can't find stylesheet to import.当我在此文件中包含 SMUI 建议的以下代码以使用自定义 colors 时,它告诉我Can't find stylesheet to import.

@use "@material/theme" with (
    $primary: #5466F9,
    $secondary: #14a564,
    $surface: #fff,
    $background: #fff
);

I can confirm that the @material/theme directory does exist inside of node_modules.我可以确认@material/theme目录确实存在于 node_modules 中。 Can anyone help me understand why this would be causing such an error?谁能帮我理解为什么这会导致这样的错误? Thanks!谢谢!

This seems like the same issue as this one on the GitHub issue tracker:似乎与 GitHub 问题跟踪器上的问题相同:

The solution should be to delete node_modules and package-lock.json and reinstall.解决方法应该是删除node_modulespackage-lock.json并重新安装。

rm -r node_modules
rm package-lock.json
npm install

Svelte Material UI was recently updated (improved performance!) and the latest install instructions work well for Sapper. Svelte Material UI 最近更新了(提高了性能!),最新的安装说明适用于 Sapper。 If you are dealing with a similar error in a Sapper app, I would recommend the following steps:如果您正在处理 Sapper 应用程序中的类似错误,我建议您执行以下步骤:

  1. uninstall rollup-plugin-postcss and sass卸载 rollup-plugin-postcss 和 sass
  2. uninstall v2 SMUI components, eg npm uninstall @smui/textfield卸载 v2 SMUI 组件,例如npm uninstall @smui/textfield
  3. install v3 SMUI components, eg npm install --save-dev @smui/textfield安装 v3 SMUI 组件,例如npm install --save-dev @smui/textfield
  4. follow the install instructions referenced above for sapper按照上面提到的安装说明进行安装

This fixed it for me to allow me to provide a custom theme in src/theme/_smui-theme.scss这为我修复了它,允许我在src/theme/_smui-theme.scss中提供自定义主题

For non-sapper projects this may work .对于非工兵项目,这可能有效 It was the inspiration beyond this fix above for sapper.这是 sapper 的上述修复之外的灵感。 Thanks to Hunter, the creator of SMUI, for his help in fixing this and for an awesome library!感谢 SMUI 的创建者 Hunter 帮助解决了这个问题并提供了一个很棒的库!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM