forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert-css.js
More file actions
28 lines (24 loc) · 733 Bytes
/
insert-css.js
File metadata and controls
28 lines (24 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const wrapper = (id, css, webpackHMREnabled = false) => `
function createStyleNode(id, content) {
var styleNode =
document.getElementById(id) || document.createElement('style');
styleNode.setAttribute('id', id);
styleNode.type = 'text/css';
if (styleNode.styleSheet) {
styleNode.styleSheet.cssText = content;
} else {
styleNode.innerHTML = '';
styleNode.appendChild(document.createTextNode(content));
}
document.head.appendChild(styleNode);
}
createStyleNode(
${JSON.stringify(id)},
${JSON.stringify(css)}
);
${webpackHMREnabled ? 'module.hot.accept()' : ''}
`;
export default function(id, css, webpackHMREnabled) {
const result = wrapper(id, css || '', webpackHMREnabled);
return result;
}