Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function saveLess (file, done) {
var lessCode = fs.readFileSync(file.filename, 'utf8')
less.render(lessCode, {
paths: [ // Specify search paths for @import directives
root,
path.join(opts.main, 'node_modules', 'bleh', 'shared')
],
filename: file.name, // Specify a filename, for better error messages
compress: false // Minify CSS output
}, function (err, cssCode) {
if (err) {
return done(err)
}
var cachebust = MD5(cssCode.css).substring(0, 8)
var name = file.filename.replace(root + path.sep, '')
var view = getViewName({
name: name.replace('.less', '')
})
var uri = assetsUri + view + '.css'
it('should have a valid less syntax', function(done) {
less
.render(formatter(dictionary))
.then(function(output) {
assert.isDefined(output);
done();
})
.catch(function(err) {
done(new Error(err));
});
});
});
(function (code) {
less.render(code, {
plugins: [new Est()],
modifyVars: {
'support-ie-version': '7',
'use-autoprefixer': 'false'
}
}).then(function (output) {
var compiled = output.css;
try {
compiled = postcss([
perfectionist({
maxSelectorLength: 1
})
]).process(compiled).css;
} catch (e) {
console.log(e);
console.log(compiled);
function compileLess(file, watch) {
var dir = path.dirname(file.path)
var name = path.basename(file.path, '.less')
console.log('[编译文件]'.green, file.path)
less.render(file.contents, {
paths: ['.', './common-less'],
}, function (e, output) {
console.log('[编译完成]'.green, file.path)
fs.writeFileSync(dir + '/' + name + '.wxss', output.css)
console.log('[写入文件]'.green, name + '.wxss')
if (watch) {
console.log('[编译完成]'.green, name + '.wxss')
console.log('[监听更改]'.green, '...')
}
});
}
return new Promise((resolve, reject) => {
less.render(data, setting, (err, d) => {
if (err) {
reject(err)
return
}
resolve(d.css)
})
})
}
less: function(str){
var ret;
str = str.replace(/\\n/g, '\n');
require('less').render(str, function(err, css){
if (err) throw err;
ret = '<style type="text/css">' + css.replace(/\n/g, '\\n') + '</style>';
});
return ret;
},
fs.readFile(path, 'utf-8', function(err, lessSource) {
if (err) return cb(err);
var options = {filename: path};
less.render(lessSource, options, function(err, css) {
if (err) {
cb(formatError(err));
return;
}
cb(null, css);
});
});
};
async function loadStyles() {
const lessData = readFileSync(`${__dirname}/style/style.less`, 'utf8');
const {css} = await less.render(lessData, {
paths: [resolve(`${__dirname}/..`)],
filename: 'style.less'
});
const node = document.createElement("style");
node.innerHTML = css;
document.head.appendChild(node);
}
export const getClasses = (css: string, fileName: string) => {
try {
const fileType = getFileType(fileName);
let transformedCss = '';
if (fileType === FileTypes.less) {
less.render(css, { asyncImport: true } as any, (err, output) => {
transformedCss = output.css.toString();
});
} else if (fileType === FileTypes.scss) {
const filePath = getFilePath(fileName);
transformedCss = sass
.renderSync({
data: css,
includePaths: [filePath],
})
.css.toString();
} else {
transformedCss = css;
}
const processedCss = processor.process(transformedCss);
var lessPromise = new Promise((resolve, reject) => {
less
.render(src, { paths: [path.dirname(filename), appRoot] })
.then(result => {
resolve(result.css);
})
.catch(reject);
});
return lessPromise;