mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-02 12:07:54 +08:00
31 lines
896 B
JavaScript
31 lines
896 B
JavaScript
const less = require('less');
|
|
const { readFileSync } = require('fs');
|
|
const path = require('path');
|
|
const postcss = require('postcss');
|
|
const NpmImportPlugin = require('less-plugin-npm-import');
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
function transformLess(lessFile, config = {}) {
|
|
const { cwd = process.cwd() } = config;
|
|
const resolvedLessFile = path.resolve(cwd, lessFile);
|
|
|
|
let data = readFileSync(resolvedLessFile, 'utf-8');
|
|
data = data.replace(/^\uFEFF/, '');
|
|
|
|
// Do less compile
|
|
const lessOpts = {
|
|
paths: [path.dirname(resolvedLessFile)],
|
|
filename: resolvedLessFile,
|
|
plugins: [new NpmImportPlugin({ prefix: '~' })],
|
|
javascriptEnabled: true,
|
|
};
|
|
return less
|
|
.render(data, lessOpts)
|
|
.then(result => postcss([autoprefixer]).process(result.css, { from: undefined }))
|
|
.then(r => {
|
|
return r.css;
|
|
});
|
|
}
|
|
|
|
module.exports = transformLess;
|