惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
The GitHub Blog
The GitHub Blog
小众软件
小众软件
美团技术团队
博客园 - 司徒正美
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
J
Java Code Geeks
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
V
V2EX
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog

虹墨空间站

联想拯救者 Y700 四代(TB322FC)刷入澎湃 OS 3 教程 各种 AI 工具来来回回切模型太麻烦?Bifrost 自建 AI 网关,实现模型切换自由 跨域预检请求失败问题分析 垃圾京东云 浏览器直接访问正常,过了负载均衡就崩了?只因响应头里多了个空格 Claude Code 怎样快速消耗 token 去掉高德地图开屏广告 解决 Claude Code 安装或更新后 claude.exe 无法运行、claude native binary not installed Windows 11 26H1 显示所有托盘图标 OpenClaw 安装与配置 盘点手里的电子产品传家宝 基于 7z 的 NAS 到网盘备份解决方案,支持增量、分卷、加密、压缩 卸载百度网盘智能看图 在线工具 - 富文本转 Markdown 2025 年了,安卓平板上什么第三方九键输入法最好用? 鸿蒙 PC 编译运行 Electron 应用 bat 脚本打印输出彩色文字 Android 强制锁定屏幕旋转方向
CDN 方式引入 Monaco Editor
iMaeGoo · 2025-09-01 · via 虹墨空间站

在前端工程中可以用 @monaco-editor/loader 来引入 Monaco,但有时候我们的前端项目不依赖 Webpack、Vite 等打包工具,如何在普通网页中用纯 CDN 的方式引入 Monaco Editor?

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title>Monaco Editor</title>
<style>
body {
margin: 0;
padding: 0;
}
#editor {
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<div id="editor"></div>
<script src="https://registry.npmmirror.com/monaco-editor/0.52.2/files/min/vs/loader.js"></script>
<script>
require.config({
paths: {
vs: "https://registry.npmmirror.com/monaco-editor/0.52.2/files/min/vs",
},
});
window.MonacoEnvironment = {
getWorkerUrl: function (workerId, label) {
return `data:text/javascript;charset=utf-8,${encodeURIComponent(
'self.MonacoEnvironment={baseUrl:"https://registry.npmmirror.com/monaco-editor/0.52.2/files/min/"};' +
'importScripts("https://registry.npmmirror.com/monaco-editor/0.52.2/files/min/vs/base/worker/workerMain.js");'
)}`;
},
};
require(["vs/editor/editor.main"], function () {
const editorElement = document.getElementById("editor");
const editor = monaco.editor.create(editorElement, {
value:
"function main() {\n console.log('Hello, iMaeGoo!');\n}\n\nmain();\n",
language: "javascript",
});
window.addEventListener("resize", () =>
editor.layout({
width: editorElement.offsetWidth,
height: editorElement.offsetHeight,
})
);
});
</script>
</body>
</html>

效果