mya-parser-vue-loader
Version:
A parser plugin for mya to parser vue component.
33 lines (26 loc) • 971 B
JavaScript
var uglifyJS = require('uglify-js');
function insertCSS(styleContent, moduleId) {
function updateStyle(styleNode, content) {
if (styleNode.styleSheet) {
styleNode.styleSheet.cssText = content;
} else {
// styleNode.appendChild(document.createTextNode(content));
styleNode.innerHTML = content;
}
}
var styleNode = document.querySelectorAll('[data-id="' + moduleId + '"]');
if (styleNode.length) {
updateStyle(styleNode[0], styleContent);
return ;
}
// 首次插入,内容为空,则不创建 style 标签
if (!styleContent) {
return ;
}
styleNode = document.createElement('style');
styleNode.setAttribute('type', 'text/css');
styleNode.setAttribute('data-id', moduleId);
updateStyle(styleNode, styleContent);
document.head.appendChild(styleNode);
};
module.exports = uglifyJS.minify(insertCSS.toString(), {fromString: true}).code;