gxd-vue-library
Version:
依赖与element Ui插件库,聚福宝福利PC端插件库
65 lines (51 loc) • 1.82 kB
JavaScript
;
const fileHelper = require('./../fileHepler');
const basePath = require('./../path');
const clog = require('./../clog');
const {
logsLine,
randomChar
} = require('./../lib/utils');
function init(params){
let hashWoff = randomChar('10');
let hashTtf = randomChar('10');
clog('开始复制文件', 'blueBG');
logsLine(clog, 'start');
let path = basePath.buildDistDirectory + '/static/css/app.css';
let res = fileHelper.readFileSync(path);
let reg = /(url)(.*?)(\.(woff|ttf))/g;
let contentArr = res.match(reg);
let settings = {};
if(fileHelper.existFileSync(`${basePath.rootDir}/settings.js`)) {
settings = require(`${basePath.rootDir}/settings.js`);
}
let reString = '/';
if(settings.custom_project_root) {
reString = `/${settings.custom_project_root}/`
}
contentArr.map(item=>{
if(item.indexOf('../../') !== -1) {
let oldStr = item;
let newStr = item.replace('../../', reString);
res = res.replace(oldStr, newStr);
clog(`原路径:${oldStr}`, 'green');
clog(`新路径:${newStr}`, 'green');
}
});
//解决element icon显示乱码问题
res = res.replace(/535877f5/g,hashWoff)
res = res.replace(/732389de/g,hashTtf)
fileHelper.renameFileSync(
`${basePath.buildDistDirectory}/static/fonts/element-icons.535877f5.woff`,
`${basePath.buildDistDirectory}/static/fonts/element-icons.${hashWoff}.woff`,
)
fileHelper.renameFileSync(
`${basePath.buildDistDirectory}/static/fonts/element-icons.732389de.ttf`,
`${basePath.buildDistDirectory}/static/fonts/element-icons.${hashTtf}.ttf`,
)
fileHelper.writeFileSync(path, res);
clog(`更新${reString}/static/css/app.css文件成功`, 'green');
clog(`${JSON.stringify(params, null,2)}`, 'cyan');
logsLine(clog);
}
module.exports = init;