import fs from 'fs'; const useref = /(.*?)/ms; const generateBalise = (type, output, body, opts = {}) => { switch (type) { case 'css': return ``; case 'js': return ``; case 'keep': return opts[output] ? body : ''; } }; export default function (src, opts) { let html = fs .readFileSync(src) .toString() .replace(/>\n+\s*/g, '>'); while (useref.test(html)) { const [raw, type, output, body] = useref.exec(html); html = html.replace(raw, generateBalise(type, output, body, opts)); } return html; }