本文共 2991 字,大约阅读时间需要 9 分钟。
上一篇:Theia架构
本指南将教你如何构建你自己的Theia应用。
你需要安装node 10版本(译者:事实上最新的node稳定版即可):
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bashnvm install 10
以及yarn:
npm install -g yarn
还需要确保已安装python 2.x,可通过python --version来检查。
首先请创建一个空目录,然后切换到这个目录下:
mkdir my-appcd my-app
在这个目录下创建package.json:
{ "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、运行时和构建时的依赖关系等。
首先,安装所有的依赖项。
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] XXXXXerror /theiaide/node_modules/XXXXX: Command failed.Exit code: 1Command: node-gyp rebuildArguments:Directory: /theiaide/node_modules/XXXXXOutput:gyp info it worked if it ends with okgyp info using node-gyp@3.8.0gyp info using node@8.15.0 | linux | x64gyp http GET https://nodejs.org/download/release/v8.15.0/node-v8.15.0-headers.tar.gzgyp WARN install got an error, rolling back installgyp ERR! configure errorgyp ERR! stack Error: read ECONNRESETgyp ERR! stack at TLSWrap.onread (net.js:622:25)gyp ERR! System Linux 3.10.0-862.11.6.el7.x86_64gyp 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/XXXXXgyp 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/
转载地址:http://fmxii.baihongyu.com/