Sublime Text3 配置 NodeJs 環境

來源:互聯網
上載者:User

標籤:nodejs   ram   git安裝   git   osx   nod   and   www   config   

來源於:http://www.cnblogs.com/qiaojie/p/5560388.html

前言

大家都知道,Sublime Text 安裝外掛程式一般從 Package Control 中直接安裝即可,當我安裝 node js 外掛程式時候,直接通過Package Control 安裝,雖然外掛程式安裝成功了,但是找不到設定檔 Nodejs.sublime-build 來更改一些配置 。於是去 https://packagecontrol.io/packages/Nodejs 官網上查看,只提供一種安裝方式。

安裝git安裝
  • MacOSX
    git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Nodejs

  • Windows
    git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Nodejs

  • Linux
    git clone https://github.com/tanepiper/SublimeText-Nodejs $HOME/.config/sublime-text-3/Packages/Nodejs

手動安裝

通過地址https://github.com/tanepiper/SublimeText-Nodejs去github上下載該包,解壓放到Sublime Text3\Packages 目錄下。

修改設定檔 (兩處要修改)Nodejs.sublime-settings

在 Sublime Text 3 Packages 檔案目錄下, 找到 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": "D:\\Program Files\\nodejs\\node.exe" ,  // Same for NPM command  "npm_command": "D:\\Program Files\\nodejs\\npm.cmd",  // as ‘NODE_PATH‘ environment variable for node runtime  "node_path": false,  "expert_mode": false,  "ouput_to_new_tab": false}

注: 修改了兩個地方,分別是 node_command 和 npm_command

Nodejs.sublime-build

在 Sublime Text 3 Packages 檔案目錄下, 找到 Nodejs.sublime-build 檔案,更改以下內容

修改後的檔案
{

"cmd": ["node", "$file"],
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",  "selector": "source.js",  "shell":true,  "encoding": "utf8",  "windows":    {        "cmd": ["taskkill","/F", "/IM", "node.exe","&","node", "$file"]    },  "linux":    {        "cmd": ["killall node; node", "$file"]    },    "osx":    {    "cmd": ["killall node; node $file"]    }}

注: 修改了兩個地方,分別是 encoding 和 windows 下的cmd ,windows 下的cmd命令是每次執行的時候都會kill 掉以前啟動的nodejs 進程,這個命令有些錯誤,我們修改它,到達我們想要的效果

測試

建立一個 test.js 檔案 輸入以前內容

var http = require(‘http‘);var os = require(‘os‘); http.createServer(function (request, response) {  response.writeHead(200, {‘Content-Type‘: ‘text/plain‘});  response.end(‘Hello World\n‘); }).listen(3000); console.log(‘Server running at http://127.0.0.1:3000/‘);

Ctrl +B 編譯一下,會在Sublime Text 控制台 看到 Server running at http://127.0.0.1:3000/ ,接下來我們從瀏覽器開啟 訪問 http://127.0.0.1:3000/ .

 

Sublime Text3 配置 NodeJs 環境

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.