# Build Instructions (Windows)
遵循下面的引導,在 Windows 上構建 Electron .
## 前提
* Windows 7 / Server 2008 R2 or higher
* Visual Studio 2013 with Update 4 - [download VS 2013 Community Edition for
free](https://www.visualstudio.com/news/vs2013-community-vs).
* [Python 2.7](http://www.python.org/download/releases/2.7/)
* [Node.js](http://nodejs.org/download/)
* [Git](http://git-scm.com)
如果你現在還沒有安裝 Windows , [modern.ie](https://www.modern.ie/en-us/virtualization-tools#downloads) 有一個 timebombed 版本的 Windows ,你可以用它來構建 Electron.
構建 Electron 完全的依賴于命令行,并且不可通過 Visual Studio.
可以使用任何的編輯器來開發 Electron ,未來會支持 Visual Studio.
**注意:** 雖然 Visual Studio 不是用來構建的,但是它仍然
**必須的** ,因為我們需要它提供的構建工具欄.
**注意:** Visual Studio 2015 不可用. 請確定使用 MSVS
**2013**.
## 獲取代碼
```powershell
$ git clone https://github.com/electron/electron.git
```
## Bootstrapping
bootstrap 腳本也是必要下載的構建依賴,來創建項目文件.注意我們使用的是 `ninja` 來構建 Electron,所以沒有生成 Visual Studio 項目.
```powershell
$ cd electron
$ python script\bootstrap.py -v
```
## 構建
創建 `Release` 、 `Debug` target:
```powershell
$ python script\build.py
```
可以只創建 `Debug` target:
```powershell
$ python script\build.py -c D
```
創建完畢, 可以在 `out/D`(debug target) 或 `out\R` (release target) 下面找到 `electron.exe`.
## 64bit Build
為了構建64位的 target,在運行 bootstrap 腳本的時候需要使用 `--target_arch=x64` :
```powershell
$ python script\bootstrap.py -v --target_arch=x64
```
其他構建步驟完全相同.
## Tests
測試你的修改是否符合項目代碼風格,使用:
```powershell
$ python script\cpplint.py
```
測試有效性使用:
```powershell
$ python script\test.py
```
在構建 debug 時為 Tests包含原生模塊 (例如 `runas`) 將不會執行(詳情 [#2558](https://github.com/electron/electron/issues/2558)), 但是它們在構建 release 會起效.
運行 release 構建使用 :
```powershell
$ python script\test.py -R
```
## 解決問題
### Command xxxx not found
如果你遇到了一個錯誤,類似 `Command xxxx not found`, 可以嘗試使用 `VS2012 Command Prompt` 控制臺來執行構建腳本 .
### Fatal internal compiler error: C1001
確保你已經安裝了 Visual Studio 的最新安裝包 .
### Assertion failed: ((handle))->activecnt >= 0
如果在 Cygwin 下構建的,你可能會看到 `bootstrap.py` 失敗并且附帶下面錯誤 :
```
Assertion failed: ((handle))->activecnt >= 0, file src\win\pipe.c, line 1430
Traceback (most recent call last):
File "script/bootstrap.py", line 87, in <module>
sys.exit(main())
File "script/bootstrap.py", line 22, in main
update_node_modules('.')
File "script/bootstrap.py", line 56, in update_node_modules
execute([NPM, 'install'])
File "/home/zcbenz/codes/raven/script/lib/util.py", line 118, in execute
raise e
subprocess.CalledProcessError: Command '['npm.cmd', 'install']' returned non-zero exit status 3
```
這是由同時使用 Cygwin Python 和 Win32 Node 造成的 bug.解決辦法就是使用 Win32 Python 執行 bootstrap 腳本 (假定你已經在目錄 `C:\Python27` 下安裝了 Python):
```powershell
$ /cygdrive/c/Python27/python.exe script/bootstrap.py
```
### LNK1181: cannot open input file 'kernel32.lib'
重新安裝 32位的 Node.js.
### Error: ENOENT, stat 'C:\Users\USERNAME\AppData\Roaming\npm'
簡單創建目錄 [應該可以解決問題](http://stackoverflow.com/a/25095327/102704):
```powershell
$ mkdir ~\AppData\Roaming\npm
```
### node-gyp is not recognized as an internal or external command
如果你使用 Git Bash 來構建,或許會遇到這個錯誤,可以使用 PowerShell 或 VS2012 Command Prompt 來代替 .
- 介紹
- 常見問題
- Electron 常見問題
- 向導
- 支持平臺
- 分發應用
- 提交應用到 Mac App Store
- 打包應用
- 使用 Node 原生模塊
- 主進程調試
- 使用 Selenium 和 WebDriver
- 使用開發人員工具擴展
- 使用 Pepper Flash 插件
- 使用 Widevine CDM 插件
- 教程
- 快速入門
- 桌面環境集成
- 在線/離線事件探測
- API文檔
- 簡介
- 進程對象
- 支持的 Chrome 命令行開關
- 環境變量
- 自定義的 DOM 元素
- File 對象
- &lt;webview&gt; 標簽
- window.open 函數
- 在主進程內可用的模塊
- app
- autoUpdater
- BrowserWindow
- contentTracing
- dialog
- globalShortcut
- ipcMain
- Menu
- MenuItem
- powerMonitor
- powerSaveBlocker
- protocol
- session
- webContents
- Tray
- 在渲染進程(網頁)內可用的模塊
- desktopCapturer
- ipcRenderer
- remote
- webFrame
- 在兩種進程中都可用的模塊
- clipboard
- crashReporter
- nativeImage
- screen
- shell
- 開發
- 代碼規范
- 源碼目錄結構
- 與 NW.js(原 node-webkit)在技術上的差異
- 構建系統概覽
- 構建步驟(OS X)
- 構建步驟(Windows)
- 構建步驟(Linux)
- 在調試中使用 Symbol Server