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]("}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章