罗欣大B
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.

44 lines
1.7 KiB

const fs = require('fs');
//引入路径模块
const path = require("path");
function process(html) {
html = html.replace(/static\/js\//g, "itax-base/static/js/");;
return html;
}
function processHtml(html) {
html = html.replace(/static\/favicon\.ico/g, "./static/favicon.ico");;
return html;
}
//# sourceMappingURL=pi-ui.umd.js.map
function processMap(html) {
html = html.replace(/\/\/# sourceMappingURL=pi-ui\.umd\.js\.map/g, "");;
return html;
}
//拼接用来读取的文件路径,当前路径加上config.js
let pathName = path.join(__dirname, "../itax-base/static/js")
// 同步读取上级目录下的所有文件到files中
const files = fs.readdirSync(pathName);
const manifestFileName = files.find(file => file.indexOf('manifest') > -1)
const manifestFilePath = pathName + '/' + manifestFileName
const content = fs.readFileSync(manifestFilePath)
fs.writeFileSync(manifestFilePath, process(content.toString()))
// 解决找不到pi-ui.umd.js.map浏览器有警告问题
const vendorFileName = files.find(file => file.indexOf('vendor') > -1)
const vendorFilePath = pathName + '/' + vendorFileName
const vendorContent = fs.readFileSync(vendorFilePath)
fs.writeFileSync(vendorFilePath, processMap(vendorContent.toString()))
// 设置html中favicon.ico的引用路径
let pathNameHtml = path.join(__dirname, "../itax-base")
const htmlFiles = fs.readdirSync(pathNameHtml);
const htmlFileName = htmlFiles.filter(file => file.indexOf('.html') > -1)
if (htmlFileName) {
htmlFileName.forEach(item => {
let htmlFilePath = pathNameHtml + '/' + item
let htmlContent = fs.readFileSync(htmlFilePath)
fs.writeFileSync(htmlFilePath, processHtml(htmlContent.toString()))
})
}