我正在使用Svelte和材料设计库Svelte材料UI进行一个项目。
这个材料设计库需要SASS,所以我安装了一个带有npm install svelte-preprocess的预处理器,并在rollup.config.js中添加了preprocess: autoPreprocess()。所以我现在有:
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:
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";。
我得到的不是运行应用程序的端口的成功消息,而是:
[!] 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)我做错了什么?
发布于 2020-06-21 20:07:20
我从未使用@import从NPM包中导入组件,但在您所引用的自述包中,建议使用“从”svelte-material“导入x”。还请注意,您所引用的包将不支持svelte-预处理,请查看自述:
要将其捆绑在自己的代码中,请使用Sass处理器(不是Sass Svelte预处理器,而是Sass处理器)。
发布于 2020-06-30 11:04:34
我也遇到了同样的问题,我设法用rollup-plugin-postcss插件修复了这个问题。用下面的代码更新您的rollup.config.js,您的sass目录中应该有_smui-theme.scss。
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'] }]]
})https://stackoverflow.com/questions/62501496
复制相似问题