2.0.0 • Published 3 years ago

replace-lz v2.0.0

Weekly downloads
2
License
ISC
Repository
-
Last release
3 years ago

#这是一个替换的包

const fs = require("fs");
//封装class方法
class Replace {
    constructor(opt) {
        //合并参数
        Object.assign(this, opt);
        //读取到这些文件里面的内容
        const htmlCon = fs.readFileSync(this.htmlSrc, "utf-8");
        const csslCon = fs.readFileSync(this.cssSrc, "utf-8");
        const jslCon = fs.readFileSync(this.jsSrc, "utf-8");
        //为新文件的内容进行复制  也就是替换的过程
        const str = htmlCon.replace("//css替换项", `<style>${csslCon}</style>`).replace("//js替换项", `<script>${jslCon}</script>`);
        //把替换后的内容写入到html文件中
        fs.writeFileSync(this.htmlSrc, str);
    }
}
new Replace({
    htmlSrc: "src/index.html",
    cssSrc: "src/index.css",
    jsSrc: "src/index.js"
})