繁体   English   中英

如何在 esbuild 中成功构建 monaco-editor?

[英]How do I successfully build monaco-editor in esbuild?

我在不同的平台上尝试过相同的配置,它们都可以工作,而在 esbuild 中它会导致错误

构建:

esbuild.build({
  entryPoints: ['node_modules/monaco-editor/esm/vs/editor/editor.worker.js'],
  outfile: outfile,
  bundle: true,
  format: 'iife'
}).then(() => {
  console.log('Build complete, save at ' + outfile)
})

然后我在项目中引用如下

self.MonacoEnvironment = {
  getWorker() {
    return new Worker('/assets/editor.worker.js')
  },
}
import(
  'monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution'
).then(() => {
  import('monaco-editor').then(({ editor }) => {
    editor.create(container.current, {
      language: 'typescript',
    })
  })
})

最终控制台报告运行时错误,我发现工作文件已被正确引用,错误似乎是由于走这段代码造成的

if (!initialized) {
  initialize(null);
}

在此处输入图像描述

我只需要将导入的编辑器的目录更改为 api

import('monaco-editor/esm/vs/editor/editor.api').then(({ editor }) => {
  editor.create(container.current, {
    language: 'typescript',
  })
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM