mirror of
https://github.com/chinchang/web-maker.git
synced 2025-08-02 11:30:22 +02:00
make monaco stylesheet insert just once
This commit is contained in:
@@ -181,7 +181,9 @@ export default class CodeEditor extends Component {
|
|||||||
|
|
||||||
async loadDeps() {
|
async loadDeps() {
|
||||||
if (this.props.type === 'monaco' && !isMonacoDepsLoaded) {
|
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(
|
return import(/* webpackChunkName: "monaco" */ '../lib/monaco/monaco.bundle.js').then(
|
||||||
() => {
|
() => {
|
||||||
isMonacoDepsLoaded = true;
|
isMonacoDepsLoaded = true;
|
||||||
|
@@ -305,11 +305,14 @@ export function loadJS(src) {
|
|||||||
return d.promise;
|
return d.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadCss(src) {
|
export function loadCss({ url, id }) {
|
||||||
var d = deferred();
|
var d = deferred();
|
||||||
var style = window.document.createElement('link');
|
var style = window.document.createElement('link');
|
||||||
style.setAttribute('href', src);
|
style.setAttribute('href', url);
|
||||||
style.setAttribute('rel', 'stylesheet');
|
style.setAttribute('rel', 'stylesheet');
|
||||||
|
if (id) {
|
||||||
|
style.setAttribute('id', id);
|
||||||
|
}
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
style.onload = function() {
|
style.onload = function() {
|
||||||
d.resolve();
|
d.resolve();
|
||||||
|
Reference in New Issue
Block a user