简体   繁体   English

在 VS Code 中将 V8 设置为 JavaScript 运行时(而不是 Node.js)

[英]Set V8 as JavaScript run-time in VS Code (instead of Node.js)

"A curious not expert here." “一个好奇的不是这里的专家。” I have learned that Node.js uses V8 as its JavaScript run-time.我了解到 Node.js 使用 V8 作为其 JavaScript 运行时。 In Visual Studio Code we set a "type: node" configuration to execute scripts against Node.js.在 Visual Studio Code 中,我们设置了一个“type: node”配置来针对 Node.js 执行脚本。 But Node.js seems to be too much for my needs as I just want to execute some simple JavaScript functions and I don't need DOM nor Node.js API's either.但是 Node.js 似乎无法满足我的需求,因为我只想执行一些简单的 JavaScript 函数,而且我也不需要 DOM 和 Node.js API。

So I was wondering if there is a way to use V8 directly as the run-time of my script and set in VS Code something like the following code so Node.js isn't needed.所以我想知道是否有一种方法可以直接使用 V8 作为我的脚本的运行时,并在 VS Code 中设置类似于以下代码的内容,因此不需要 Node.js。

{
    "type": "V8",
    "request": "launch",
    "name": "Launch JS script",
    "program": "${workspaceFolder}/app.js",
    "runtimeExecutable": "V8_compilation_folder"
}

I guess I would need to compile V8 (which apparently doesn't seem to be very straight forward btw) and set the output compilation path in VS Code configuration.我想我需要编译 V8(顺便说一句,这显然不是很直接)并在 VS Code 配置中设置输出编译路径。 I'm not even sure if this question makes sense at all, but I think it would be more practical for my simple scripts.我什至不确定这个问题是否有意义,但我认为这对我的简单脚本更实用。

No, you can't run code with just V8.不,您不能仅使用 V8 运行代码。 You need some wrapper around it to feed it code and provide some way to get results out of it.您需要一些包装器来为它提供代码并提供一些方法来从中获取结果。 There also isn't any benefit to running without an environment around it.在没有周围环境的情况下运行也没有任何好处。

Plain V8 doesn't even know how to load scripts/modules and run them and it has no ability to communicate with the outside world as all of that comes from the host that runs it. Plain V8 甚至不知道如何加载脚本/模块并运行它们,并且它无法与外部世界进行通信,因为所有这些都来自运行它的主机。 node.js loads things dynamically as you need them so until you load anything, it's basically just V8 plus a module system and memory management. node.js 会根据您的需要动态加载内容,因此在您加载任何内容之前,它基本上只是 V8 加上模块系统和内存管理。 It's what you need to "just run" Javascript.这就是“运行”Javascript 所需要的。

Look in the Javascript specification.查看 Javascript 规范。 There's no file I/O, no networking, etc... It's just a language and it needs a run-time library and host environment with it to do something useful.没有文件 I/O,没有网络等......它只是一种语言,它需要一个运行时库和宿主环境来做一些有用的事情。 That's what node.js is - an environment to make it useful.这就是 node.js 是什么 - 一个使它有用的环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM