1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-09 16:06:21 +02:00

make monaco stylesheet insert just once

This commit is contained in:
Kushagra Gour
2018-12-10 19:18:39 +05:30
parent eb139c8b40
commit 8310b4aa4c
2 changed files with 8 additions and 3 deletions

View File

@ -181,7 +181,9 @@ export default class CodeEditor extends Component {
async loadDeps() {
if (this.props.type === 'monaco' && !isMonacoDepsLoaded) {
loadCss('lib/monaco/monaco.css');
if (!$('#monaco-css')) {
loadCss({ url: 'lib/monaco/monaco.css', id: 'monaco-css' });
}
return import(/* webpackChunkName: "monaco" */ '../lib/monaco/monaco.bundle.js').then(
() => {
isMonacoDepsLoaded = true;

View File

@ -305,11 +305,14 @@ export function loadJS(src) {
return d.promise;
}
export function loadCss(src) {
export function loadCss({ url, id }) {
var d = deferred();
var style = window.document.createElement('link');
style.setAttribute('href', src);
style.setAttribute('href', url);
style.setAttribute('rel', 'stylesheet');
if (id) {
style.setAttribute('id', id);
}
document.head.appendChild(style);
style.onload = function() {
d.resolve();