本文整理汇总了TypeScript中less.render函数的典型用法代码示例。如果您正苦于以下问题:TypeScript render函数的具体用法?TypeScript render怎么用?TypeScript render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: compile
exports.compile = function compile(buffer, stream) {
var m = less.render(buffer, function (e, css) {
if (e)
throw new Error(e);
stream.write(css);
});
};
示例2: switch
const compile_and_resolve_deps = (input: {code: string, lang: string, file: string}) => {
let code: string
switch (input.lang) {
case "coffeescript":
try {
code = coffee.compile(input.code, {bare: true, shiftLine: true})
} catch (error) {
return reply({error: mkCoffeescriptError(error, input.file)})
}
break;
case "javascript":
case "typescript":
code = input.code
break;
case "less":
const options = {
paths: [path.dirname(input.file)],
compress: true,
ieCompat: false,
}
less.render(input.code, options, (error: any, output: any) => {
if (error != null)
reply({error: mkLessError(error, input.file)})
else
reply({code: output.css})
})
return
default:
throw new Error(`unsupported input type: ${input.lang}`)
}
const result = ts.transpileModule(code, {
fileName: input.file,
reportDiagnostics: true,
compilerOptions: {
noEmitOnError: false,
noImplicitAny: false,
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
},
})
if (result.diagnostics != null && result.diagnostics.length > 0) {
const diagnostic = result.diagnostics[0]
return reply({error: mkTypeScriptError(diagnostic)})
}
const source = result.outputText
try {
const deps = detective(source)
return reply({ code: source, deps: deps })
} catch(error) {
return reply({error: error})
}
}
示例3: less
function less(input: Buffer, options: LessOptions, callback: TransformCallback) {
const input_string = input.toString('utf8');
less_module.render(input_string, options, (less_error, less_output) => {
if (less_error) {
const error = new Error(less_error.message)
Object.assign(error, less_error)
return callback(error);
}
const output = new Buffer(less_output.css, 'utf8');
callback(null, output);
});
}
示例4: render
render(data) {
let newLessStyles = data.less;
for (let key in data.theme) {
newLessStyles = newLessStyles.replace(new RegExp(variableRegexPrefix + key + variableRegexPostfix), () => {
return '@' + key + ': ' + data.theme[key] + ';';
});
}
Less.render(newLessStyles, (e, result) => {
if (result !== undefined) {
this.reply({
method: 'render',
css: result.css
});
}
});
}
示例5: task
task("styles:build", async () => {
for (const src of paths.less.sources) {
const {css} = await less.render(read(src)!, {filename: src})
write(rename(src, {dir: paths.build_dir.css, ext: ".css"}), css)
}
})
示例6: render
// .less
const less = {
render(
source: string,
map: any | null,
options: any
): StylePreprocessorResults {
const nodeLess = require('less')
let result: any
let error: Error | null = null
nodeLess.render(
source,
{ syncImport: true },
(err: Error | null, output: any) => {
error = err
result = output
}
)
if (error) return { code: '', errors: [error] }
if (map) {
return {
code: result.css.toString(),
map: merge(map, result.map),
errors: []
}
}
return { code: result.css.toString(), errors: [] }
示例7: render
// .less
const less = {
render(
source: string,
map: any | null,
options: any
): StylePreprocessorResults {
const nodeLess = require('less')
let result: any
let error: Error | null = null
nodeLess.render(
source,
Object.assign({}, options, { syncImport: true }),
(err: Error | null, output: any) => {
error = err
result = output
}
)
if (error) return { code: '', errors: [error] }
if (map) {
return {
code: result.css.toString(),
map: merge(map, result.map),
errors: []
}
}
return { code: result.css.toString(), errors: [] }