保定大屏项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

74 lines
2.2 KiB

#!/usr/bin/env node
/**
* 这个方法用来处理 css-modlue
* 由于没有开源插件,所以自己撸了一个
*/
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const getLocalIdentName = require("./getLocalIdentName");
const AddlocalIdentName = require("./AddlocalIdentName");
const replacedefaultLess = require("./replacedefaultLess");
// read less file list
const lessArray = ['@import "../node_modules/antd/lib/style/themes/default.less";'];
const loopAllLess = parents => {
const promiseList = [];
glob
.sync(`${parents}/**/**.less`, { ignore: "**/node_modules/**" })
.filter(
filePath =>
!filePath.includes("ant.design.pro.less") &&
!filePath.includes("global.less")&&
!filePath.includes("light.style.less")&&
!filePath.includes("dark.style.less")&&
!filePath.includes("lightblue.style.less")
)
.forEach(relaPath => {
// post css add localIdentNameplugin
const fileContent = replacedefaultLess(relaPath);
// push less file
promiseList.push(
AddlocalIdentName(
relaPath,
fileContent,
getLocalIdentName(relaPath)
).then(result => {
lessArray.push(result);
})
);
});
return Promise.all(promiseList);
};
class mergeLessPlugin {
constructor(options) {
const defaulOptions = {
stylesDir: path.join(__dirname, `..${path.sep}src${path.sep}`),
outFile: path.join(__dirname, `..${path.sep}.temp${path.sep}ant-design-pro.less`),
};
this.options = Object.assign(defaulOptions, options);
this.generated = false;
}
apply(compiler) {
const { options } = this;
compiler.plugin("emit", (compilation, callback) => {
const { outFile } = options;
// covert less
if (fs.existsSync(outFile)) {
fs.unlinkSync(outFile);
} else if (!fs.existsSync(path.dirname(outFile))) {
fs.mkdirSync(path.dirname(outFile));
}
lessArray.splice(1, lessArray.length);
loopAllLess(options.stylesDir).then(() => {
fs.writeFileSync(outFile, lessArray.join("\n"));
callback();
});
});
}
}
module.exports = mergeLessPlugin;