sublime text 3 下的nodejs環境配置以及新增nodejs的操作按鈕實現殺死node程序(加快捷鍵)
阿新 • • 發佈:2019-02-19
首先感謝http://blog.csdn.net/ender__/article/details/53289066作者提供的幫助,前期的配置和他的配置相同。
首先謝謝我參考的環境配置同學的資料
https://my.oschina.NET/ximidao/blog/413101
在該操作基礎上
安裝nodejs的外掛後,環境配置成功後的兩個檔案內容
Nodejs.sublime-build
- {
- "cmd": ["node", "$file"],
- //"cmd": ["node","--debug", "–use-strict", "–harmony","-p", "$file"],
-
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
- "selector": "source.js",
- "shell":true,
- "encoding": "utf8",
- "windows":
- {
- //"cmd": ["call","killnodejs.bat $file"]
- //"cmd": ["taskkill /F /IM node.exe & node $file"]
- "cmd": ["node", "$file"]
- },
- "linux":
- {
-
"cmd": ["killall node; node $file"]
- },
- "osx":
- {
- "cmd": ["killall node; node $file"]
- }
- }
然後是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": "C:\\Program Files\\nodejs\\node.exe",
- // Same for NPM command
- "npm_command": "C:\\Program Files\\nodejs\\npm.cmd",
- // as 'NODE_PATH' environment variable for node runtime
- //"node_path": false,
- "expert_mode": true,
- "ouput_to_new_tab": false
- }
{ "id": "nodejsstop", "caption": "Stop", "command": "node_stop" }, 在Context.sublime-menu檔案 { "id": "nodejsrun", "caption": "Run", "command": "node_run" },後新增一行以下內容
{ "id": "nodejsstop", "caption": "Stop", "command": "node_stop" }, 在檔案Default.sublime-commands內容為 {
"caption": "Nodejs::Run::Current File",
"command": "node_run"
}, 的後面新增
{
"caption": "Nodejs::Stop::Current File",
"command": "node_stop"
}, 在Nodejs.py檔案 內容為
- # Command to Run node
- class NodeRunCommand(NodeTextCommand):
- def run(self, edit):
- command = """kill -9 `ps -ef | grep node | grep -v grep | awk '{print $2}'`"""
- os.system(command)
- command = ['node', self.view.file_name()]
- self.run_command(command, self.command_done)
- def command_done(self, result):
- s = sublime.load_settings("Nodejs.sublime-settings")
- if s.get('output_to_new_tab'):
- self.scratch(result, title="Node Output", syntax="Packages/JavaScript/JavaScript.tmLanguage")
- else:
- self.panel(result)
- # Command to Stop node
- class NodeStopCommand(NodeTextCommand):
- def run(self, edit):
- command = """kill -9 `ps -ef | grep node | grep -v grep | awk '{print $2}'`"""
- os.system(command)
- command = 'taskkill /F /IM node.exe'#the command when os is win,then run cmd command
- result = os.system(command)
- s = sublime.load_settings("Nodejs.sublime-settings")
- if s.get('output_to_new_tab'):
- self.scratch(result, title="Node Output", syntax="Packages/JavaScript/JavaScript.tmLanguage")
- else:
- self.panel(result)
實現了關閉由sublime開啟的nodejs程序。