How to use the Compiler function from stylus

Find comprehensive JavaScript stylus.Compiler code examples handpicked from public code repositorys.

stylus.Compiler is a class in Stylus, a CSS preprocessor, that compiles Stylus code into CSS.

463
464
465
466
467
468
469
470
471
472
473
  };
}


function urlResolver(options = {}) {
  function resolver(url) {
    const compiler = new _stylus.Compiler(url);
    const {
      filename
    } = url;
    compiler.isURL = true;
fork icon1
star icon0
watch icon1

How does stylus.Compiler work?

stylus.Compiler is a class that compiles Stylus code into CSS code by parsing, evaluating, and generating CSS code from the input Stylus code. It takes a Stylus AST (Abstract Syntax Tree) as input, compiles it, and returns a string of CSS code. The class provides methods for compiling a single file or a string of Stylus code, and it supports various options for configuring the compilation process, such as including and excluding certain files and defining custom functions and variables.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
const stylus = require("stylus");

const style = `
body
background-color: #f5f5f5
color: #333
`;

const compiler = new stylus.Compiler(style);
compiler.compile((err, css) => {
  if (err) throw err;
  console.log(css);
});

In this example, we create a stylus.Compiler instance with a Stylus string. We then call the compile method on the compiler instance to compile the Stylus into CSS. The compiled CSS is passed to a callback function that logs it to the console.