我当前的项目使用grunt-sass将scss文件转换为css。根据grunt-sass文档,除少数几个以外,我可以使用node-sass提供的任何选项:
选件
请参阅node-sass选项,但文件,outFile,成功,错误除外。
我的项目从一个SCSS文件中编译出两个CSS文件。SCSS文件中包含if语句,根据版本变量的值提供不同的代码($ bootstrap-version:3;或$ bootstrap-version:4;)。
我想使用node-sass选项functions
将引导程序版本返回到我的SCSS文件。
这是我的gruntfile。该functions: {...}
路是我本来期望的选择工作。
// Compile Sass
sass: {
bootstrap3: {
options: {
style: 'expanded'
functions: {getBootstrapVersion: function(){return 3;}}
},
files: {
'dist/bootstrap3/css/my-bs3-variation.css': './bootstrap3/scss/my-bs3-variation.scss'
},
},
bootstrap4: {
options: {
style: 'expanded',
functions: {getBootstrapVersion: function(){return 4;}}
},
files: {
'dist/bootstrap4/css/my-bs4-variation.css': './bootstrap4/scss/my-bs4-variation.scss'
}
}
在SCSS文件中,我这样调用该函数:
$bootstrap-version: getBootstrapVersion();
h1:before {
content: "Bootstrap " + $bootstrap-version + " Version of ";
}
但是,当尝试对其进行编译时,我得到了>> Error: error in C function getBootstrapVersion: A SassValue object was expected.
调用函数所在行的错误信息。
node-sass文档中的示例对我没有太大帮助。我做错了什么?还是有我没有找到的更好的例子?
我使用grunt-sass版本2.0.0和node-sass版本4.7.2
函数必须返回一个SassValue
对象。
不幸的是,我认为grunt-sass
单独使用它是不可能的,因为我们需要包装您返回的数字4
和3
键入中定义的函数node-sass
(grunt-sass
不会公开...)。
例如,使用javascript中的node-sass时,可能会使用类似于声明为Number的方式。sass.types.Number(4)
4
SassValue
这sass
是node-sass import const sass = require('node-sass');
,在grunt中不可用...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句