首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是什么原因导致在这个小巧的掌声中无法编译SASS?

是什么原因导致在这个小巧的掌声中无法编译SASS?
EN

Stack Overflow用户
提问于 2020-06-21 16:37:39
回答 2查看 1.1K关注 0票数 0

我正在使用Svelte和材料设计库Svelte材料UI进行一个项目。

这个材料设计库需要SASS,所以我安装了一个带有npm install svelte-preprocess的预处理器,并在rollup.config.js中添加了preprocess: autoPreprocess()。所以我现在有:

代码语言:javascript
复制
plugins: [
    svelte({
        // enable run-time checks when not in production
        dev: !production,
        // we'll extract any component CSS out into
        // a separate file - better for performance
        css: css => {
            css.write('public/build/bundle.css');
        },
        preprocess: autoPreprocess()
    }),
    routify({ singleBuild : true}),
    replace({
      // stringify the object
      APPENV: JSON.stringify({         
          isProd: production,
          ...config().parsed // attached the .env config            
      }),
  }),
  // more stuff
]

我有一个包含以下内容的文件smui.js

代码语言:javascript
复制
import Button from '@smui/button';
import Checkbox from '@smui/checkbox';
import Chips from '@smui/chips';
import Dialog from '@smui/dialog';
import FormField from '@smui/form-field';
import Select from '@smui/select';

export {
  Button,
  Checkbox,
  Chips,
  Dialog,
  FormField,
  Select
}

在我的index.svelte文件中,我以这样的方式导入上面的内容:import * as Smui from "../smui.js";

我得到的不是运行应用程序的端口的成功消息,而是:

代码语言:javascript
复制
[!] Error: Unexpected character '@' (Note that you need plugins to import files that are not JavaScript)
node_modules\@smui\dialog\_index.scss (1:0)
1: @import "smui-theme";
   ^
2: @import "./style";
Error: Unexpected character '@' (Note that you need plugins to import files that are not JavaScript)

我做错了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-21 20:07:20

我从未使用@import从NPM包中导入组件,但在您所引用的自述包中,建议使用“从”svelte-material“导入x”。还请注意,您所引用的包将不支持svelte-预处理,请查看自述:

要将其捆绑在自己的代码中,请使用Sass处理器(不是Sass Svelte预处理器,而是Sass处理器)。

票数 0
EN

Stack Overflow用户

发布于 2020-06-30 11:04:34

我也遇到了同样的问题,我设法用rollup-plugin-postcss插件修复了这个问题。用下面的代码更新您的rollup.config.js,您的sass目录中应该有_smui-theme.scss

代码语言:javascript
复制
import postcss from 'rollup-plugin-postcss'
...

plugins: [
        svelte({
            // enable run-time checks when not in production
            dev: !production,
            // we'll extract any component CSS out into
            // a separate file - better for performance
            css: css => {
                css.write('public/build/bundle.css')
            }
        }),

        postcss({
            extensions: ['.css'],
            extract: true,
            minimize: true,
            use: [['sass', { includePaths: ['./src/(yoursass-directory-name)', './node_modules'] }]]
        })
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62501496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档