默认已经安装好sublime、node和npm
1、sublime的node.js插件下载
由于在package control上经常下载失败,所以这里直接从GitHub上进行下载!
GitHub下载地址:https://github.com/tanepiper/SublimeText-Nodejs,下载ZIP压缩包。
2、node.js插件安装
(1)解压第2步中下载的压缩包SublimeText-Nodejs-master.zip
(2)打开目录..\Sublime Text 3\Packages,打开方式如下:
(3)在目录中新建名为“Nodejs”的文件夹,将解压的插件文件拷贝进去,拷贝后效果如下图所示:
3、node.js插件配置
(1)用sublime打开nodejs插件文件夹中的 Nodejs.sublime-build 文件并做如下修改,修改后保存:
{
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "utf8", #这里修改
"windows":
{
#这里修改了 ,前面的是为了避免使用utf8 引起的编码错误 这个的意思 主要是 先杀死所有node进程然后在启动node进程
"cmd": ["chcp", "", "&", "taskkill", "/F", "/IM", "node.exe", "&", "node", "$file"]
},
"linux":
{
"cmd": ["killall node; node $file"]
},
"osx":
{
"cmd": ["killall node; node $file"]
}
}
(2)再用sublime打开nodejs插件文件夹中的 Nodejs.sublime-settings 文件并做如下修改,修改后保存:
{
// 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": "F:\\nodejs\\node.exe", //node.exe 的位置
// Same for NPM command
"npm_command": "F:\\nodejs\\npm.cmd", //npm.cmd 的位置
// as 'NODE_PATH' environment variable for node runtime
"node_path":true, "expert_mode": false, "ouput_to_new_tab": false,
}
(3)创建一个 js 文件写入代码:
console.log("hello");
然后按下 ctrl + B 进行 Build 如果控制台提示:
说明配置成功!
ERROR原因:cmd 在启动一个新的node时需要杀掉之前开启的node.exe,如果没有开启,就会提示ERROR没有找到node.exe进程。