+
{
diff --git a/packages/design/components/MonacoEditor/components/Preview/index.html b/packages/design/components/MonacoEditor/components/Preview/index.html
index cf0d287..d2b5e66 100644
--- a/packages/design/components/MonacoEditor/components/Preview/index.html
+++ b/packages/design/components/MonacoEditor/components/Preview/index.html
@@ -38,9 +38,10 @@
const compileScript = document.createElement('script');
compileScript.id = CompileScriptId;
compileScript.type = 'module';
- compileScript.innerHTML = `try{${code}}catch(err){console.log(err)}`;
+ compileScript.innerHTML = `${code}`;
document.body.appendChild(compileScript);
+ // code runner exhibition
document.getElementById('__CODE_RUN__').innerHTML = runcode.replace(
/[\n]/g,
'
'
diff --git a/packages/design/components/MonacoEditor/plugins/initPlugin.ts b/packages/design/components/MonacoEditor/plugins/initPlugin.ts
index bc094fd..e42edff 100644
--- a/packages/design/components/MonacoEditor/plugins/initPlugin.ts
+++ b/packages/design/components/MonacoEditor/plugins/initPlugin.ts
@@ -1,24 +1,28 @@
import { Monaco } from '@monaco-editor/react';
import REACT_TYPES from '!!raw-loader!/node_modules/@types/react/index.d.ts';
+import REACT_DOM_TYPES from '!!raw-loader!/node_modules/@types/react-dom/client.d.ts';
const InitPlugin = (monaco: Monaco) => {
// 添加ts编译设置
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.Latest,
- allowNonTsExtensions: true,
- moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
- module: monaco.languages.typescript.ModuleKind.ES2015,
+ moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs, // 模块解析策略 nodejs
+ module: monaco.languages.typescript.ModuleKind.ES2015, // 代码生成格式
noEmit: true,
- esModuleInterop: true,
+ esModuleInterop: true, // 通过为所有导入创建命名空间对象,实现CommonJS和ES模块之间的互操作性
jsx: monaco.languages.typescript.JsxEmit.React,
reactNamespace: 'React',
allowJs: true,
- typeRoots: ['node_modules/@types'],
+ typeRoots: ['node_modules/@types'], // 声明类型依赖目录
});
/** 添加额外的依赖包,lib是源代码,第二个参数是自己为其设置的文件路径*/
monaco.languages.typescript.typescriptDefaults.addExtraLib(
REACT_TYPES,
- 'file:///node_modules/@react/types/index.d.ts'
+ 'file:///node_modules/@types/react/index.d.ts'
+ );
+ monaco.languages.typescript.typescriptDefaults.addExtraLib(
+ REACT_DOM_TYPES,
+ 'file:///node_modules/@types/react-dom/client.d.ts'
);
};
diff --git a/packages/design/tsconfig.json b/packages/design/tsconfig.json
index 43e9f42..769d5af 100644
--- a/packages/design/tsconfig.json
+++ b/packages/design/tsconfig.json
@@ -4,6 +4,6 @@
"exclude": ["lib", ".*"],
"compilerOptions": {
"baseUrl": ".",
- "outDir": "lib",
+ "outDir": "lib"
}
}