fix: load css data instead of loading css bundle file when js is loaded

This commit is contained in:
Shariq Ansari 2022-10-10 21:01:28 +05:30
parent 4a3259ed92
commit 09f9cda115
2 changed files with 9 additions and 13 deletions

View file

@ -383,16 +383,6 @@ async function write_assets_json(metafile) {
key = `rtl_${key}`;
}
out[key] = asset_path;
} else if (Object.keys(info.inputs).length !== 0) {
for (let input in info.inputs) {
if (input.includes(".vue?type=style")) {
// remove hash from css file name
let key = path.basename(asset_path);
key = key.split(".css")[0];
key = key.substring(0, key.lastIndexOf(".")) + ".css";
out[key] = asset_path;
}
}
}
}

View file

@ -13,9 +13,15 @@ module.exports = {
let asset_path = "/" + path.relative(sites_path, out.path);
let dir = path.dirname(out.path);
if (out.path.endsWith(".js") && keys.includes(asset_path)) {
let bundle_css = files[asset_path];
let include_css = '\nfrappe.require("' + bundle_css + '");\n';
let modified = include_css + out.text;
let name = out.path.split(".bundle.")[0];
name = path.basename(name);
let related_css_file = result.outputFiles.filter((f) => {
return f.path.endsWith(".css") && f.path.includes(`/${name}.bundle.`);
});
let css_data = JSON.stringify(related_css_file[0].text).slice(1, -1);
let modified = `frappe.dom.set_style("${css_data}");\n` + out.text;
out.contents = Buffer.from(modified);
}
if (!fs.existsSync(dir)) {