vue使用monaco editor时报错 Unexpected usage at EditorSimpleWorker.loadForeignModule
# 在 vue-cli 中
// vue.config.js
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
module.exports = {
chainWebpack(config) {
config.plugin('monaco').use(new MonacoWebpackPlugin())
},
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# 在vite中使用
在调用monaco-editor的组件中,如下是vue3.2 tsx中使用json的例子 当前环境: vite:2.8.0, monaco-editor:0.33.0,vue:3.2.25
import * as Monaco from 'monaco-editor'
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
// @ts-ignore
self.MonacoEnvironment = {
getWorker: function (_: any, label: string) {
console.log(label)
if (label === 'json') {
return new jsonWorker()
}
new editorWorker()
},
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
上次更新: 2024/01/30, 00:35:17
- 02
- Node与GLIBC_2.27不兼容解决方案08-19
- 03
- Git清空本地文件跟踪缓存08-13