简体   繁体   English

用 npm 编译内联 sass?

[英]Compile inline sass with npm?

Is there a straightforward way to do this?有没有一种简单的方法可以做到这一点? I've tried using sass, node-sass, and tinysass, and nothing works.我试过使用 sass、node-sass 和 tinysass,但没有任何效果。 I just want to compile inline sass in javascript, something like this:我只想在 javascript 中编译内联 sass,如下所示:

import sassPkg from 'sass-pkg'

const style = `body{ .container{ color: red } }`
const result = sassPkg.compile(style)

It seems like this should be easy to do but it's not.看起来这应该很容易做到,但事实并非如此。 I'd also be willing to settle for loading the sass from an external file, but I really don't think that should be necessary, and anyway I haven't been able to do that either.我也愿意满足于从外部文件加载 sass,但我真的认为这没有必要,而且无论如何我也无法做到这一点。

You can use node-sass您可以使用节点萨斯

import * as sass from 'node-sass';

const style = `body{ .container{ color: red } }`
const result = sass.renderSync({
  data: style
});

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

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