How to use the render function from less

Find comprehensive JavaScript less.render code examples handpicked from public code repositorys.

83
84
85
86
87
88
89
90
91
92
        })(`./build/themes/V3/${dir}/style.css`);
}

await fs.outputFile('./themes/themes.json', JSON.stringify(themes, null, 2));

// await less.render(lessCode, {
//      compress  : !dev,
//      sourceMap : (dev ? {
//              sourceMapFileInline: true,
//              outputSourceFiles: true
fork icon294
star icon882
watch icon36

+ 11 other calls in file

63
64
65
66
67
68
69
70
71
72
        return; 
}

if($.is.less(source) && jdf.config.build.less){
        try{
                Less.render(sourceContent, {filename: source, syncImport:true}, function(error, output){
                        if(error){
                                console.log(error);
                        }else{
                                var targetContent = output.css;
fork icon160
star icon614
watch icon56

+ 3 other calls in file

107
108
109
110
111
112
113
114
115
116
const customInclude = this.customStylesInclude()
// now render both together
const lessOptions = {
  paths: [this.dir]
}
less.render(themeLess + customInclude, lessOptions, (err, output) => {
  if (err) return done(err)
  const filename = this.opts.stylesheetName || 'theme.css'
  const dest = path.join(this.dest, 'public', filename)
  fs.mkdirpSync(path.join(this.dest, 'public'))
fork icon82
star icon657
watch icon20

+ 3 other calls in file

195
196
197
198
199
200
201
202
203
204
  filename: lessPath,
  paths: options.preprocess.importPaths(options.render.paths, req)
});
lessSrc = options.preprocess.less(lessSrc, req);

less.render(lessSrc, renderOptions, function(err, output){
  if (err) {
    utilities.lessError(err);
    return next(err);
  }
fork icon77
star icon269
watch icon10

+ 3 other calls in file

87
88
89
90
91
92
93
94
95
96

const isProductionEnv = process.env.NODE_ENV === 'production';

const processLess = function(context, payload) {
  return new Promise(( resolve, reject ) => {
    less.render({
      file: context
    }, function(err, result) {
      if( !err ) {
        resolve(result);
fork icon52
star icon233
watch icon4

+ 7 other calls in file

129
130
131
132
133
134
135
136
137
138

function compileLess() {
  const lessContent = fs.readFileSync(path.resolve(docsDir, 'src/docs.less'), {
    encoding: 'utf8',
  });
  less.render(
    lessContent,
    {
      paths: [path.resolve(__dirname, '../src')],
      filename: 'docs.css',
fork icon25
star icon78
watch icon34

+ 3 other calls in file

63
64
65
66
67
68
69
70
71
72

process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (less_css) {
  less.render(less_css, function(e, css){
    console.log(css)
  });
});
"""
fork icon22
star icon61
watch icon6

+ 3 other calls in file

124
125
126
127
128
129
130
131
132
133
    res.end(err.message);
    return;
}

var contentText = fs.readFileSync(path);
less.render(contentText.toString(), {
    filename: path
}, function(e, output) {
    if (e) {
        res.end(self.showError(e));
fork icon18
star icon56
watch icon4

+ 3 other calls in file

76
77
78
79
80
81
82
83
84
85
    return locals;
}

export default async function processLess(source, rootPath, filePath, camelCase, modulePath) {
    try {
        const lessResult = await less.render(source, {
            sourceMap: {
                outputSourceFiles: true
            },
            relativeUrls: true,
fork icon1
star icon10
watch icon2

+ 3 other calls in file

33
34
35
36
37
38
39
40
41
        }
    };
};

async function compileLess (file, minify) {
    return less.render(await fs.readFileAsync(file, 'utf8'), { filename: file, strictMath: true }).then((output) => {
        return minify ? minifyCss(output.css) : output.css;
    });
}
fork icon65
star icon0
watch icon1

36
37
38
39
40
41
42
43
44
45
}

const lessSource = `.css {
  ${content}
}`
let { css } = await less.render(lessSource)
css = css.split('\n')

content = ''
for (let i = 0; i < css.length; i++) {
fork icon27
star icon214
watch icon5

+ 3 other calls in file

19
20
21
22
23
24
25
26
27
    main: main[i],
    accent: accent[i],
    accentLight: accentLight[i]
  })
  var name = names[i].toLowerCase().replace(' ', '-')
  less.render(text, {
    paths: ['.'], compress: true, filename: name
  }, save.bind(null, '../build/themes/' + name + '.css'))
}
fork icon5
star icon35
watch icon5

+ 3 other calls in file

10
11
12
13
14
15
16
17
18
19
const transform = (code, fp, opts)=>imports.add(fp);

transform.generate = async (dev=false)=>{
        clearLessCache();
        const lessCode = Array.from(imports).reverse().map((fp)=>`@import (less) "${fp}";`).join('\n');
        return await LessLib.render(lessCode, {
                compress  : !dev,
                sourceMap : (dev ? {
                        sourceMapFileInline: true,
                        outputSourceFiles: true
fork icon13
star icon11
watch icon4

24
25
26
27
28
29
30
31
32
33
function read(done) {
  fs.readFile(path, 'utf8', done);
}

// Compile the source.
// Use the less.render() promise interface because the regular one appears
// to occasionally call the callback multiple times.
function compile(source, done) {
  less.render(source, opts)
    .then(function(output) { done(null, output); },
fork icon1
star icon0
watch icon44

+ 11 other calls in file

95
96
97
98
99
100
101
102
103
104
darkTheme = darkTheme.replace(/\@secondary-color/, settings.secondaryColor);
darkTheme = darkTheme.replace("@islight", true ? '@light' : '@dark');
darkTheme = darkTheme.replace("@isdark", !true ? '@light' : '@dark');

//alert(theme);
less.render(lightTheme, {}, function (error, output) {
    console.log(error, output);
    //alert(output);
    fs.writeFileSync(process.env.PWD + '/themes/' + settings.theme + '/css/light.css', output.css);
});
fork icon0
star icon6
watch icon3

+ 7 other calls in file

18
19
20
21
22
23
24
25
26
27
}, defaults)

const collection = new Xstatic.collection('less', [ files ], options)

function less(file, doc, resolver) {
  return Less.render(doc.body.data.toString(), _.merge(options.less, {
    plugins: [ resolver ],
    filename: Path.resolve(file.path),
    relativeUrls: false,
  })).then(function(result) {
fork icon2
star icon2
watch icon2

24
25
26
27
28
29
30
31
32
33
  },
}

const compileLess = async (filePath) => {
  const source = await readFile(filePath, 'utf8')
  const { css } = await render(source, {
    filename: filePath,
    plugins: [TildeResolverPlugin],
  })
  return css
fork icon46
star icon0
watch icon0

67
68
69
70
71
72
73
74
75
76

// process less content
let processed;

try {
  processed = await less.render(input, options);
} catch (error) {
  console.log(
    `[${blue('.scripts/less')}] ${red(
      'An error occurred while processing styles'
fork icon0
star icon1
watch icon1

+ 6 other calls in file

223
224
225
226
227
228
229
230
231
232
233
        files: scripts,
    }, fork);
};


actions.buildCSS = async function buildCSS(data) {
    const lessOutput = await less.render(data.source, {
        paths: data.paths,
        javascriptEnabled: false,
    });

fork icon1
star icon0
watch icon5

+ 3 other calls in file

238
239
240
241
242
243
244
245
246
247
async function saveRenderedCss(data) {
	if (!data.customCSS) {
		return;
	}
	const less = require('less');
	const lessObject = await less.render(data.customCSS, {
		compress: true,
		javascriptEnabled: false,
	});
	data.renderedCustomCSS = lessObject.css;
fork icon0
star icon0
watch icon1