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

推荐订阅源

博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
aimingoo的专栏
aimingoo的专栏
B
Blog
小众软件
小众软件
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
L
LangChain Blog
WordPress大学
WordPress大学
罗磊的独立博客
GbyAI
GbyAI
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
美团技术团队
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub 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>

效果