如何解决(插件 postcss)错误:找不到要导入的文件或无法读取:smui-theme. Material UI Svelte 项目

V. *_*bor 8 sass material-ui rollupjs svelte

我正在将Material UI集成到 Svelte 项目中。

我遵循文档中的所有内容,但是在运行我的项目时出现此错误:

!] (plugin postcss) Error: File to import not found or unreadable: smui-theme.
node_modules/@smui/tab/_index.scss
Error: File to import not found or unreadable: smui-theme.
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?

V. *_*bor 10

该错误意味着您必须调用一个文件_smui-theme.scss才能编译 Sass。

首先确保您_smui-theme.scss的项目theme目录下有该文件。(我通常把它放进去src/theme/_smui-theme.scss

然后你必须postcss像这样将它添加到你的汇总插件的配置中:

import postcss from 'rollup-plugin-postcss';

export default {
    ...
    plugins: [
        svelte({
            ...
        }),

        ....

        postcss({
            extract: true,
            minimize: true,
            use: [
                ['sass', {
                    includePaths: [
                        './src/theme',     <<< ------------ HERE    
                        './node_modules'
                    ]
                }]
            ]
        }),
        ...
};
Run Code Online (Sandbox Code Playgroud)

确保该theme目录很好地包含在postcss插件配置中,如前所示。

注意:如果路径不对,你可能会收到同样的错误!