Deno如今能够编译为独立的自包含二进制文件

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Deno 1.6引入了"},{"type":"link","attrs":{"href":"https:\/\/deno.land\/posts\/v1.6","title":"","type":null},"content":[{"type":"text","text":"将Deno项目编译成独立的可执行文件的功能"}]},{"type":"text","text":",这种文件在"},{"type":"link","attrs":{"href":"https:\/\/deno.land\/posts\/v1.7","title":"","type":null},"content":[{"type":"text","text":"Deno 1.7中被进一步缩小"}]},{"type":"text","text":"(高达60%)。Deno现在有一个专门的语言服务器,旨在提升Deno开发者在代码编辑器中的体验。Deno还增加了对data URL的支持,使计算机生成的代码能够得以执行。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Deno 1.6的发布说明对新的编译工具链做出了如下的阐述:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"deno compile"}]},{"type":"text","text":"为Deno所做的事情类似于"},{"type":"link","attrs":{"href":"https:\/\/github.com\/nexe\/nexe","title":"","type":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"nexe"}]}]},{"type":"text","text":"或"},{"type":"link","attrs":{"href":"https:\/\/github.com\/vercel\/pkg","title":"","type":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"pkg"}]}]},{"type":"text","text":"为Node所做的事情:根据JavaScript或TypeScript源码创建一个独立的、自包含的二进制文件。这是Deno issue跟踪器上被投票最多的一个问题。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"将Deno应用编译成自包含的二进制文件解决了与Node或"},{"type":"link","attrs":{"href":"https:\/\/nectar.js.org\/","title":"","type":null},"content":[{"type":"text","text":"Nectarjs JavaScript原生编译器"}]},{"type":"text","text":"相同的使用场景。例如,有些开发人员可能想要为他们的应用程序创建一个闭源的商业方案\/演示\/试用版本;将他们的应用作为一个单独的文件部署在一系列的平台上,或者为了实现可移植性,在可执行文件中合并其他资产。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"发布说明提供了一个使用新编译特性的样例:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Deno编译器可以将代码编译到任意支持的架构(Windows x64、MacOS x64和Linux x64),这与执行编译的计算机所使用的架构无关。这意味着,一台Linux机器能够创建适用于Windows或MacOS的可执行文件。借助"},{"type":"codeinline","content":[{"type":"text","text":"--lite"}]},{"type":"text","text":"选项(Deno 1.7中可用),所生成的二进制文件能够小40-60%。"},{"type":"codeinline","content":[{"type":"text","text":"deno compile"}]},{"type":"text","text":"还可以创建内置CA证书、自定义V8标记、限定的Deno权限以及预填充命令行参数的二进制文件。然而,它也有一些限制。Deno编译器不支持"},{"type":"link","attrs":{"href":"https:\/\/github.com\/denoland\/deno\/issues\/8654","title":"","type":null},"content":[{"type":"text","text":"web workers"}]},{"type":"text","text":"和 "},{"type":"link","attrs":{"href":"https:\/\/github.com\/denoland\/deno\/issues\/8655","title":"","type":null},"content":[{"type":"text","text":"动态导入"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Deno 1.6引入了一个新的"},{"type":"codeinline","content":[{"type":"text","text":"lsp"}]},{"type":"text","text":"子命令,它会启动一个实现了"},{"type":"link","attrs":{"href":"https:\/\/microsoft.github.io\/language-server-protocol\/","title":"","type":null},"content":[{"type":"text","text":"语言服务器协议(Language Server Protocol,LSP)的语言服务器"}]},{"type":"text","text":"。LSP定义了代码编辑器或集成开发环境与语言服务器之间的协议,从而能够提供一些便利的特性,比如代码补全、跳至定义处(go-to-definition)或代码lint。目前,"},{"type":"codeinline","content":[{"type":"text","text":"deno lsp"}]},{"type":"link","attrs":{"href":"https:\/\/github.com\/denoland\/deno\/issues\/8643","title":"","type":null},"content":[{"type":"text","text":"实现了"}]},{"type":"text","text":"代码补全、悬停提示、跳至定义处和跳至引用处等操作。"},{"type":"link","attrs":{"href":"https:\/\/marketplace.visualstudio.com\/items?itemName=denoland.vscode-deno","title":"","type":null},"content":[{"type":"text","text":"Deno VSCode扩展"}]},{"type":"text","text":"目前还没有支持"},{"type":"codeinline","content":[{"type":"text","text":"deno lsp"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Deno 1.7添加了对"},{"type":"link","attrs":{"href":"https:\/\/deno.land\/posts\/v1.7#support-for-importing-data-urls","title":"","type":null},"content":[{"type":"text","text":"data URL的支持"}]},{"type":"text","text":"。如下的"},{"type":"link","attrs":{"href":"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Basics_of_HTTP\/Data_URIs","title":"","type":null},"content":[{"type":"text","text":"data URL"}]},{"type":"text","text":" "},{"type":"codeinline","content":[{"type":"text","text":"\"data:application\/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\""}]},{"type":"text","text":"对下文所示的TypeScript源码进行了"},{"type":"link","attrs":{"href":"https:\/\/en.wikipedia.org\/wiki\/Base64","title":"","type":null},"content":[{"type":"text","text":"base64"}]},{"type":"text","text":"编码:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"export const a = \"a\";\nexport enum A {\n A,\n B,\n C,\n}\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在data URL中编码的代码可以通过常规的导入语法进行导入("},{"type":"codeinline","content":[{"type":"text","text":"import * as a from \"data:application\/typescript;base64,...\""}]},{"type":"text","text":")。该特性对于执行动态生成的内容特别有用。类似的特性被用来实现"},{"type":"link","attrs":{"href":"https:\/\/www.infoq.com\/news\/2020\/10\/svelte-simple-repl-summit-2020\/","title":"","type":null},"content":[{"type":"text","text":"Svelte前端框架的交互式训练场"}]},{"type":"text","text":"。训练场用户在文本域中输入的源码会被预处理、打包、 "},{"type":"link","attrs":{"href":"https:\/\/youtu.be\/S3j1fLzC8_E?list=PL8bMgX1kyZThM1sbYCoWdTcpiYysJsSeu&t=1976","title":"","type":null},"content":[{"type":"text","text":"通过URL对象进行导入"}]},{"type":"text","text":"、执行并在预览面板中展现。Data URL也可以用于web workers中。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Deno "},{"type":"link","attrs":{"href":"https:\/\/deno.land\/posts\/v1.6","title":"","type":null},"content":[{"type":"text","text":"1.6"}]},{"type":"text","text":"和"},{"type":"link","attrs":{"href":"https:\/\/deno.land\/posts\/v1.7","title":"","type":null},"content":[{"type":"text","text":"1.7"}]},{"type":"text","text":"的发布说明详细介绍了该版本的其他小功能。Deno是一款开源软件,采用MIT许可证。我们鼓励通过"},{"type":"link","attrs":{"href":"https:\/\/github.com\/denoland\/deno","title":"","type":null},"content":[{"type":"text","text":"Deno项目"}]},{"type":"text","text":"进行贡献,并应遵循"},{"type":"link","attrs":{"href":"https:\/\/github.com\/denolib\/awesome-deno\/blob\/master\/CONTRIBUTING.md","title":"","type":null},"content":[{"type":"text","text":"Deno贡献指南"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"原文链接:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"[Deno Now Compiles to Self-Contained, Standalone Binaries]("}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章