天天看點

【SublineText3】Nodejs sublime text 3安裝與配置

1.下載下傳subline的nodejs插件

2.解壓zip檔案, 并重命名檔案夾“Nodejs”

3.  打開sublime,操作"preference" --> "Browse packages", 打開一個目錄,複制”Nodejs“檔案夾到這個目錄

4.打開Nodejs檔案夾,找到檔案“Nodejs.sublime-build”, 拖拽到sublime

  顯示為

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

  接下來更改為

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

5.打開Nodejs檔案夾,找到檔案“Nodejs.sublime-settings”, 拖拽到sublime

  更改為

{
  // 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": false,

  "ouput_to_new_tab": false
}
      

6.使用

  建立一個test.js檔案,然後輸入測試代碼,如

for (let i = 0; i < 3; i++) {
    console.log('i:', i);
}
      

  使用快捷鍵ctrl + b運作,結果如下

i: 0
i: 1
i: 2
[Finished in 0.1s]
      

  按ESC關閉視窗

其實配置檔案不難,難的是,找到對的解決方法。網上有些配置錯誤的代碼,會有點困擾人。不過,這些都搞定啦!哈哈~

每天進步一點點,不要停止前進的腳步~