Skip to content

Commit

Permalink
2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
indooorsman committed Jan 11, 2023
1 parent 612aa4c commit 6c26f3a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## V2.7.0
- fix inject logic to avoid styles missing in some micro-frontend framework
- ***Important***: there's a breaking change of inject logic, before this version the inject method would be deleted once it's called, from this verson it will ***not*** be deleted anymore, for people using custom inject method please pay attention.

## V2.6.3
- upgrade dependencies
- fix #45 #46, thanks to @markdalgleish
Expand Down
24 changes: 11 additions & 13 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,39 @@ const getLogger = (build) => {
const buildInjectCode = (injectToSelector = 'head', css, digest, options) => {
if (typeof options.inject === 'function') {
return `
(function(){
(function(window){
const doInject = () => {
${options.inject(css, digest)}
delete window.__inject_${digest}__;
};
window.__inject_${digest}__ = doInject;
})();
})(globalThis);
`;
}
return `
(function(){
(function(win){
const css = \`${css}\`;
const doInject = () => {
if (typeof document === 'undefined') {
if (typeof win.document === 'undefined') {
return;
}
let root = document.querySelector('${injectToSelector}');
let root = win.document.querySelector('${injectToSelector}');
if (root && root.shadowRoot) {
root = root.shadowRoot;
}
if (!root) {
root = document.head;
root = win.document.head;
}
let container = root.querySelector('#_${digest}');
if (!container) {
container = document.createElement('style');
container = win.document.createElement('style');
container.id = '_${digest}';
const text = win.document.createTextNode(css);
container.appendChild(text);
root.appendChild(container);
}
const text = document.createTextNode(css);
container.appendChild(text);
delete window.__inject_${digest}__;
}
window.__inject_${digest}__ = doInject;
})();
win.__inject_${digest}__ = doInject;
})(globalThis);
`;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esbuild-css-modules-plugin",
"version": "2.6.3",
"version": "2.7.0",
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).",
"main": "./index.js",
"types": "./index.d.ts",
Expand Down

0 comments on commit 6c26f3a

Please sign in to comment.