Skip to content

Commit

Permalink
fix(build): fix css injection
Browse files Browse the repository at this point in the history
fix css injection tryiong to inject at buildtime instead of runtime
  • Loading branch information
mario-subo committed Aug 12, 2022
1 parent a0249b5 commit a03f284
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const components = require("./src/index.json");

function injectCSS(css, uniqueId) {
if (!css || typeof document === "undefined") {
console.error("injectCSS error: no css or document undefined ");
return;
}

const exists = !!document.querySelector(`style[id="${uniqueId}"]`);
if (exists) {
if (uniqueId && exists) {
return;
}

Expand Down Expand Up @@ -50,7 +51,7 @@ export default [
(varname, id) => {
const filePathArray = id.split("\\");
const file = filePathArray[filePathArray.length - 1].split(".");
return `${varname} = ${injectCSS(varname, `rc-${file[0]}`)};`;
return `const inject = ${injectCSS};\n${varname} = inject(${varname}, "rc-${file[0]}");`;
},
],
}),
Expand Down Expand Up @@ -78,7 +79,7 @@ export default [
(varname, id) => {
const filePathArray = id.split("\\");
const file = filePathArray[filePathArray.length - 1].split(".");
return `${varname} = ${injectCSS(varname, `rc-${file[0]}`)};`;
return `const inject = ${injectCSS};\n${varname} = inject(${varname}, "rc-${file[0]}");`;
},
],
}),
Expand Down

0 comments on commit a03f284

Please sign in to comment.