Skip to content

Commit 6c26f3a

Browse files
committed
2.7.0
1 parent 612aa4c commit 6c26f3a

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## V2.7.0
2+
- fix inject logic to avoid styles missing in some micro-frontend framework
3+
- ***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.
4+
15
## V2.6.3
26
- upgrade dependencies
37
- fix #45 #46, thanks to @markdalgleish

lib/utils.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,41 +56,39 @@ const getLogger = (build) => {
5656
const buildInjectCode = (injectToSelector = 'head', css, digest, options) => {
5757
if (typeof options.inject === 'function') {
5858
return `
59-
(function(){
59+
(function(window){
6060
const doInject = () => {
6161
${options.inject(css, digest)}
62-
delete window.__inject_${digest}__;
6362
};
6463
window.__inject_${digest}__ = doInject;
65-
})();
64+
})(globalThis);
6665
`;
6766
}
6867
return `
69-
(function(){
68+
(function(win){
7069
const css = \`${css}\`;
7170
const doInject = () => {
72-
if (typeof document === 'undefined') {
71+
if (typeof win.document === 'undefined') {
7372
return;
7473
}
75-
let root = document.querySelector('${injectToSelector}');
74+
let root = win.document.querySelector('${injectToSelector}');
7675
if (root && root.shadowRoot) {
7776
root = root.shadowRoot;
7877
}
7978
if (!root) {
80-
root = document.head;
79+
root = win.document.head;
8180
}
8281
let container = root.querySelector('#_${digest}');
8382
if (!container) {
84-
container = document.createElement('style');
83+
container = win.document.createElement('style');
8584
container.id = '_${digest}';
85+
const text = win.document.createTextNode(css);
86+
container.appendChild(text);
8687
root.appendChild(container);
8788
}
88-
const text = document.createTextNode(css);
89-
container.appendChild(text);
90-
delete window.__inject_${digest}__;
9189
}
92-
window.__inject_${digest}__ = doInject;
93-
})();
90+
win.__inject_${digest}__ = doInject;
91+
})(globalThis);
9492
`;
9593
};
9694

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "esbuild-css-modules-plugin",
3-
"version": "2.6.3",
3+
"version": "2.7.0",
44
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).",
55
"main": "./index.js",
66
"types": "./index.d.ts",

0 commit comments

Comments
 (0)