本文整理匯總了TypeScript中node-sass.render函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript render函數的具體用法?TypeScript render怎麽用?TypeScript render使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了render函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Promise
return new Promise((resolve, reject) => {
sassConfig.omitSourceMapUrl = true;
if (sassConfig.sourceMap) {
sassConfig.sourceMap = basename(sassConfig.outFile);
sassConfig.sourceMapContents = true;
}
nodeSassRender(sassConfig, (sassError: SassError, sassResult: Result) => {
const diagnostics = runSassDiagnostics(context, sassError);
if (diagnostics.length) {
printDiagnostics(context, DiagnosticsType.Sass, diagnostics, true, true);
// sass render error :(
reject(new BuildError());
} else {
// sass render success :)
renderSassSuccess(context, sassResult, sassConfig).then(outFile => {
resolve(outFile);
}).catch(err => {
reject(new BuildError(err));
});
}
});
});
示例2: Promise
return new Promise((resolve, reject) => {
sass.render(sassOpts, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result.css.toString());
}
});
});
示例3: Promise
return new Promise((resolve, reject) => {
render({
file: inFile,
outputStyle: 'nested',
outFile: outFile,
sourceMap: false,
}, (err, result) => {
if (err)
reject(err);
else
resolve(result);
});
});
示例4: Promise
return new Promise((resolve, reject) => {
sass.render({
file,
sourceMap: false
}, (err, result) => {
if (err) {
return reject(`failed to compile ${file}: ${err}`);
}
const css = result.css.toString();
postcss([autoprefixer({browsers: ['last 2 versions']}), cssnano])
.process(css)
.then(postResult => {
postResult.warnings().forEach(warn => {
console.warn(warn.toString());
});
// do not write to file if output is identical to previous version
const productionCss = postResult.css.toString();
if (resourceChecksum.update(checksums, path.basename(outputFile), productionCss)) {
console.log(`[scss]:${file}`);
fs.writeFile(outputFile, productionCss, werr => {
if (werr) {
return reject(`faile to write css file: ${outputFile}: ${werr}`);
}
resolve(`${file} compiled`);
});
} else {
console.log(`[unchanged]:${file}`);
resolve(`${file} unchanged`);
}
});
});
});
示例5: function
sass.render({
file: '/path/to/myFile.scss',
data: 'body{background:blue; a{color:black;}}',
importer: function(url, prev, done) {
// url is the path in import as is, which libsass encountered.
// prev is the previously resolved path.
// done is an optional callback, either consume it or return value synchronously.
// this.options contains this options hash, this.callback contains the node-style callback
someAsyncFunction(url, prev, function(result) {
done({
file: result.path, // only one of them is required, see section Sepcial Behaviours.
contents: result.data
});
});
// OR
var result = someSyncFunction(url, prev);
return { file: result.path, contents: result.data };
},
includePaths: ['lib/', 'mod/'],
outputStyle: 'compressed'
}, function(error, result) { // node-style callback from v3.0.0 onwards
if (error) {
console.log(error.status); // used to be "code" in v2x and below
console.log(error.column);
console.log(error.message);
console.log(error.line);
}
else {
console.log(result.css.toString());
console.log(result.stats);
console.log(result.map.toString());
// or better
console.log(JSON.stringify(result.map)); // note, JSON.stringify accepts Buffer too
}
});
示例6: done
return;
}
accum = accum + $n.getValue();
}
done(sass.types.Number(accum, unit));
}
};
const asyncFunctions: Record<string, sass.AsyncSassFunction> = {...asyncFunction, ...asyncVarArg};
const functions: sass.FunctionDeclarations = {...syncFunctions, ...asyncFunctions};
sass.render({
file: '/path/to/myFile.scss',
data: 'body{background:blue; a{color:black;}}',
functions,
importer: [anotherAsyncImporter, asyncImporter, syncImporter],
includePaths: ['lib/', 'mod/'],
outputStyle: 'compressed'
}, handleAsyncResult);
// OR
sass.render({
file: '/path/to/myFile.scss',
data: 'body{background:blue; a{color:black;}}',
importer: asyncImporter,
includePaths: ['lib/', 'mod/'],
outputStyle: 'compressed'
}, handleAsyncResult);
// OR
示例7: function
sass.render({
file: '/path/to/myFile.scss',
data: 'body{background:blue; a{color:black;}}',
importer: function(url, prev, done) {
someAsyncFunction(url, prev, function(result) {
if (result == null) {
// return null to opt out of handling this path
// compiler will fall to next importer in array (or its own default)
return null;
}
// only one of them is required, see section Sepcial Behaviours.
done({ file: result.path });
done({ contents: result.data });
});
},
includePaths: ['lib/', 'mod/'],
outputStyle: 'compressed'
}, function(error, result) { // node-style callback from v3.0.0 onwards
if (error) {
console.log(error.status, error.column, error.message, error.line);
}
else {
console.log(result.stats);
console.log(result.css.toString());
console.log(result.map.toString());
// or better
console.log(JSON.stringify(result.map)); // note, JSON.stringify accepts Buffer too
}
});
// OR
示例8: Promise
return new Promise((resolve, reject) => {
render(opts, (err, res) => {
if (err) return reject(err);
return resolve(res.css.toString("utf8"));
});
});
示例9: renderFullPage
let html = renderFullPage(
css,
renderToStaticMarkup(result.root),
JSON.stringify(state)
);
res.send(html);
} else {
next();
}
};
}
sass.render({
file: "./site.scss"
}, (error, result) => {
if (error !== undefined) {
let handleRender = getHandleRender(result.css.toString("utf8"));
let app = express();
let port = 3000;
app.use(handleRender);
app.use("/dist", express.static("dist"));
app.listen(port);
}
});
console.log("Starting up http-server on: http:127.0.0.1:3000");