本文整理匯總了TypeScript中node-sass.renderSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript renderSync函數的具體用法?TypeScript renderSync怎麽用?TypeScript renderSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了renderSync函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test(`It should import only specific custom nodes.`, () => {
const expectedResult = fs.readFileSync(`test/files/filter-import-custom.css`, {
encoding: `utf8`,
});
const options = {
customFilters: {
customMediaWidth: [
[
{ property: `type`, value: `atrule` },
{ property: `name`, value: `media` },
{ property: `params`, value: `(min-width: 42em)` },
],
],
customMediaPrint: [
[
{ property: `type`, value: `atrule` },
{ property: `name`, value: `media` },
{ property: `params`, value: `print` },
],
],
},
};
const result = sass.renderSync({
file: `test/files/filter-import-custom.scss`,
importer: magicImporter(options) as any,
}).css.toString();
expect(result).toBe(expectedResult);
});
示例2: compile
exports.compile = function compile(buffer, stream) {
stream.write(sass.renderSync({
data: buffer,
error: function (e) {
throw new Error(e);
}
}));
};
示例3: Buffer
Config.transformStyle = (source: string, url: string, d: Decorator) => {
const res = sass.renderSync({
sourceMap: true, data: source, sourceMapEmbed: true
});
const code = res.css.toString();
const base64Map = code.match(/\/\*(.*?)\*\//)[1].replace('# sourceMappingURL=data:application/json;base64,', '');
const map = JSON.parse(new Buffer(base64Map, 'base64').toString('ascii'));
return { code, source, map };
};
示例4: test
test(`Should not fail when dir is empty.`, () => {
const expectedResult = ``;
const result = sass.renderSync({
file: `test/files/glob-import-empty-dir.scss`,
importer: globImporter(),
}).css.toString();
expect(result).toBe(expectedResult);
});
示例5: test
test(`It should import only specific nodes.`, () => {
const expectedResult = fs.readFileSync(`test/files/filter-import.css`, {
encoding: `utf8`,
});
const result = sass.renderSync({
file: `test/files/filter-import.scss`,
importer: filterImporter(),
}).css.toString();
expect(result).toBe(expectedResult);
});
示例6: _compileSCSS
/**
* Compiles SCSS to CSS and passes it through Autoprefixer.
*/
static _compileSCSS(styles: string): string {
let compiled = sass.renderSync({
data: styles,
outputStyle: 'compressed'
}).css.toString();
let prefixer = autoprefixer({
browsers: ['last 2 versions', 'last 4 Android versions']
});
return postcss(prefixer).process(compiled).css;
}
示例7: test
test(`It should import files from modules.`, () => {
const expectedResult = fs.readFileSync(`test/files/package-import.css`, {
encoding: `utf8`,
});
const result = sass.renderSync({
file: `test/files/package-import.scss`,
importer: packageImporter({
cwd: `${__dirname}/files`,
}),
}).css.toString();
expect(result).toBe(expectedResult);
});