使用Theia——构建你本身的IDE

上一篇:Theia架构html

构建你本身的IDE

  本指南将教你如何构建你本身的Theia应用。node

必要条件

  你须要安装node 10版本(译者:事实上最新的node稳定版便可):python

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
nvm install 10

  以及yarn:linux

npm install -g yarn

  还须要确保已安装python 2.x,可经过python --version来检查。git

安装

  首先请建立一个空目录,而后切换到这个目录下:github

mkdir my-app
cd my-app

  在这个目录下建立package.jsontypescript

{
  "private": true,
  "dependencies": {
    "typescript": "latest",
    "@theia/typescript": "next",
    "@theia/navigator": "next",
    "@theia/terminal": "next",
    "@theia/outline-view": "next",
    "@theia/preferences": "next",
    "@theia/messages": "next",
    "@theia/git": "next",
    "@theia/file-search": "next",
    "@theia/markers": "next",
    "@theia/preview": "next",
    "@theia/callhierarchy": "next",
    "@theia/merge-conflicts": "next",
    "@theia/search-in-workspace": "next",
    "@theia/json": "next",
    "@theia/textmate-grammars": "next",
    "@theia/mini-browser": "next"
  },
  "devDependencies": {
    "@theia/cli": "next"
  }
}

  简而言之,Theia应用程序和扩展包都是Node.js包。每个包都包含一个package.json文件,里面列出了包的一些元数据,如name、version、运行时和构建时的依赖关系等。npm

  咱们来看看这个包的内容:
  • nameversion被省略了,由于咱们不打算将它做为一个依赖项来使用。同时它被标记为private,由于不打算将它发布为一个独立的Node.js包。
  • 咱们在dependencies中列出了全部运行时依赖的扩展包,如@theia/navigator
  • 咱们将@theis/cli列为构建时的依赖项,它提供了构建和运行应用程序的脚本。

构建

  首先,安装全部的依赖项。json

yarn

  而后,使用Theia CLI来构建应用程序。浏览器

yarn theia build

  yarn在咱们应用程序的上下文中查找由@theia/cli提供的theia可执行文件,而后使用theia执行build命令。这可能须要一些时间,由于默认状况下应用程序会在production模式下进行构建,即它会进行模糊处理和最小化处理。

运行

  构建完成以后,咱们就能够启动应用程序:

yarn theia start

  你能够在命令的第一个参数中指定一个workspace路径,--hostname--port选项用来指定部署的主机名和端口号。例以下面的命令在指定的位置和端口号上打开/workspace

yarn theia start /my-workspace --hostname 0.0.0.0 --port 8080

  在终端中,你应该看到Theia应用程序已经启动并监听:

   打开浏览器并输入上面显示的地址,你就能够打开应用程序了。

故障排除

经过代理构建本地依赖项

  若是你经过代理运行yarn命令,在构建本地依赖项时有可能会遇到一些问题(如onigurma),例以下面的这个错误:

[4/4] Building fresh packages...
[1/9]  XXXXX
[2/9]  XXXXX
[3/9]  XXXXX
[4/9]  XXXXX
error /theiaide/node_modules/XXXXX: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /theiaide/node_modules/XXXXX
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@8.15.0 | linux | x64
gyp http GET https://nodejs.org/download/release/v8.15.0/node-v8.15.0-headers.tar.gz
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: read ECONNRESET
gyp ERR! stack at TLSWrap.onread (net.js:622:25)
gyp ERR! System Linux 3.10.0-862.11.6.el7.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /theiaide/node_modules/XXXXX
gyp ERR! node -v v8.15.0

  这是由于node-gyp在system/NPM的代理设置中不工做。若是遇到这种状况,能够经过错误堆栈中提供的连接下载node-headers文件(如上面例子中的https://nodejs.org/download/release/v8.15.0/node-v8.15.0-headers.tar.gz),而后使用下面的命令进行构建:

npm_config_tarball=/path/to/node-v8.15.0-headers.tar.gz yarn install

 

原文地址:https://theia-ide.org/docs/composing_applications/

相关文章
相关标签/搜索