如何将V8编译的javascript变成EXE?

发布于 2024-07-27 15:25:20 字数 79 浏览 2 评论 0原文

我知道谷歌的 v8 将 javascript 编译为本机代码(如果我理解正确的话,是二进制)。
有没有办法获取输出并将其转换为exe?

I know that google's v8 compiles javascript into native machine (binary if I understand correctly) code.
Is there a way to take the output and turn it into a exe?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清秋悲枫 2024-08-03 15:25:20

我不认为您可以使用 V8 直接将一段 JavaScript 转换为可执行文件,但您可能可以制作一个将 V8 引擎与 JavaScript 捆绑在一起并作为独立运行的应用程序。

您可以在其项目页面上找到有关 V8 的所有信息。

另请注意,JavaScript 无法完全编译,因为它是一种动态语言。 对于 V8,它是 JIT 编译的(例如 .NET)。不过,仍然可以将其转换为独立的可执行文件(例如 .NET)。

如果您想开发使用要了解用于渲染的 HTML,您也可以查看 Adobe Air

I don't think you can directly turn a piece of JavaScript into an executable using V8, but you can probably make an application that bundles the V8 engine with the JavaScript and runs it as a stand-alone.

You can find all information about V8 on its project page.

Also note that JavaScript can't be completely compiled as it's a dynamic language. With V8, it's JIT-compiled (like .NET, for example.) It's still possible to turn it into a stand-alone executable though (like .NET, for example.)

If you want to develop stand-alone applications that make use of HTML for rendering, you could have a look at Adobe Air as well.

睫毛上残留的泪 2024-08-03 15:25:20

Javascript 不能只编译一次。 该语言有 eval,它的使用相当广泛。 (例如,对于 JSON)您需要携带 JIT 和整个运行时。

这里的JIT只是一种优化,并不是摆脱编译器/解释器的方法。

Javascript cannot be compiled just once. The language has eval which is pretty widely used. (for JSON for instance) You need to carry around the JIT, and the whole runtime.

JIT here is only an optimization, not the way to get rid of the compiler/interpreter.

游魂 2024-08-03 15:25:20

Node.js 嵌入 V8。 这也许是一个值得学习的好例子。

Node.js embeds V8. This might be a good example to learn from.

兰花执着 2024-08-03 15:25:20

已经有一些尝试将 js 制作成原生代码,但无论如何它都不是可以在生产中使用的东西,更多的是学术兴趣。
Rhino java 解释器可以选择将 js 转换为 (java) 字节码,因此一种方法是转换为字节码,然后使用 GCJ 从字节码转换为本机。 有一些关于 Rhino 和 GCJ 的讨论,但我不知道是否有人尝试过。 https://groups.google.com/forum /#!msg/netscape.public.mozilla.jseng/c3tqyLZ19fw/8V4HeuMtIXUJ

另一种方法是使用 Python,特别是 Py-Py,它本身是用 Python 的非标准子集 rPython 编写的。 rPython 并不适合人类使用,但它的优点是可以编译为本机。 一项有趣的(尽管有些古怪)实验是将 Javascript 编译为 Python,然后在某些情况下,Python 恰好与 rPython 一样有效,并且可以使用 rPython 编译器编译为本机。

http://mozakai.blogspot.com/2010/07 /experiments-with-static-javascript-as.html

如果 .exe 文件确实很重要,我会将 V8 与您的应用程序捆绑在一起,因为即使您可以将 js 编译为本机,如果您使用任何 eval() 或类似的。 只要您的用户不介意 8MB exe 或 8MB V8.dll 文件,编写一个将所有内容捆绑到 .exe 文件中的工具并不困难。

最后一个想法是,Big G 已经开始允许基于 Chrome 的“原生”应用程序(谷歌:“chrome 打包应用程序”)。 它们具有低级系统访问权限,可以使用 WebKit 渲染器,允许您在 CSS 和 HTML 中创建 GUI,并且它们有自己的窗口和图标,因此它们在 Chrome 内部运行并不明显。 这可能还为时过早,但在桌面应用程序领域值得关注。

There have been a few tries at making js into native code, it's not something that can be used in production by any means, more of an academic interest.
The Rhino interpreter for java has an option to make js into (java) bytecode so one approach is to convert to bytecode and then from bytecode to native with GCJ. There is some discussion about Rhino and GCJ but I don't know if anyone ever tried exactly that. https://groups.google.com/forum/#!msg/netscape.public.mozilla.jseng/c3tqyLZ19fw/8V4HeuMtIXUJ

Another approach is using Python, specifically Py-Py which itself is written in a non-standard subset of Python called rPython. rPython is not meant for human consumption but it has the benefit of being something which can be compiled to native. One interesting (albeit wacky) experiment was to compile Javascript to Python and then in some cases that Python happens to be valid as rPython and can be compiled down to native with the rPython compiler.

http://mozakai.blogspot.com/2010/07/experiments-with-static-javascript-as.html

If a .exe file is really important, I would bundle V8 with your app since even if you can compile js to native, you still need a full interpreter if you use any eval() or similar. It would not be hard to write a tool for bundling everything into an .exe file as long as your users don't mind either an 8MB exe or 8MB V8.dll file.

As a last thought, Big G has started allowing "native" apps based on chrome (google: "chrome packaged apps"). They have low level system access and can use the WebKit renderer allowing you to create your GUI in CSS and HTML and they have their own windows and icons so it is not obvious that they are running inside of chrome. This is probably still premature but it's something to keep an eye on in the desktop applications field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文