Sublime Text 2 - 使用 Node.js 构建 javascript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20597182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:50:56  来源:igfitidea点击:

Sublime Text 2 - making javascript build with Node.js

javascriptnode.jssublimetext2

提问by user3104891

I'm trying to make a Javascript build system in Sublime Text 2 using Node.js. The problem is I don't know where Node.js is installed on my mac (I installed it with mac installer and am running Mountain Lion) or how to properly assign a path variable to find it.

我正在尝试使用 Node.js 在 Sublime Text 2 中创建一个 Javascript 构建系统。问题是我不知道 Node.js 在我的 Mac 上的安装位置(我用 mac 安装程序安装了它并且正在运行 Mountain Lion)或者如何正确分配路径变量来找到它。

回答by MattDMo

If you haven't already, install Package Controlin Sublime, then install the Nodejsplugin. This should get you a lot farther than trying to build everything from scratch.

如果您还没有,在 Sublime 中安装 Package Control,然后安装Nodejs插件。与尝试从头开始构建所有内容相比,这应该会让您走得更远。

Once Nodejs is installed, open Preferences -> Package Settings -> Nodejs -> Settings - DefaultandSettings - User. Copy the entire contents of Defaultto Userso you can edit it, then close Default. (If you editDefault, any changes will be overwritten on upgrade.) Change "node_command"and "npm_command"from falseto the full path returned by running which nodeand which npmfrom Terminal.app.

一旦安装的NodeJS,打开Preferences -> Package Settings -> Nodejs -> Settings - DefaultSettings - User。复制Defaultto的全部内容User以便您可以对其进行编辑,然后关闭Default。(如果您编辑Default任何更改都将在升级时被覆盖。)更改"node_command""npm_command"false运行which nodewhich npm从 Terminal.app返回的完整路径。

For example, if which nodereturns /usr/local/bin/node, and which npmreturns /usr/local/bin/npm, then your settings file should look like this:

例如,如果which node返回/usr/local/bin/node,并which npm返回/usr/local/bin/npm,则您的设置文件应如下所示:

{
    // save before running commands
    "save_first": true,
    // if present, use this command instead of plain "node"
    // e.g. "/usr/bin/node" or "C:\bin\node.exe"
    "node_command": "/usr/local/bin/node",
    // Same for NPM command
    "npm_command": "/usr/local/bin/npm",
    // as 'NODE_PATH' environment variable for node runtime
    "node_path": false,

    "expert_mode": false,

    "ouput_to_new_tab": false
}

Save the file, and you should now be able to successfully use the commands in Tools -> Nodejs.

保存文件,您现在应该可以成功使用Tools -> Nodejs.