From 09f9cda115d0da732c6a0d5e20597fb612d778bf Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 10 Oct 2022 21:01:28 +0530 Subject: [PATCH] fix: load css data instead of loading css bundle file when js is loaded --- esbuild/esbuild.js | 10 ---------- esbuild/frappe-vue-style.js | 12 +++++++++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/esbuild/esbuild.js b/esbuild/esbuild.js index afda75ebb0..4c478274e9 100644 --- a/esbuild/esbuild.js +++ b/esbuild/esbuild.js @@ -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; - } - } } } diff --git a/esbuild/frappe-vue-style.js b/esbuild/frappe-vue-style.js index fd2a999aa6..a817ccd443 100644 --- a/esbuild/frappe-vue-style.js +++ b/esbuild/frappe-vue-style.js @@ -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)) {