2

Theia 开发环境搭建文档

官方文档:https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#prerequisites

当前搭建版本:v1.35.0

官方文档写的安装环境条件

  • Node.js >= 16.14.0 and < 17.

    • If you are interested in Theia's VS Code Extension support then you should use a Node version at least compatible with the one included in the version of Electron used by VS Code.
  • Yarn package manager >= 1.7.0 AND < 2.x.x.
  • git (If you would like to use the Git-extension too, you will need to have git version 2.11.0 or higher.)
  • Python3 is required for the build due to node-gyp@8.4.1

Some additional tools and libraries are needed depending on your platform:

  • Linux

    • make
    • gcc (or another compiling toolchain)
    • pkg-config
    • build-essential: sudo apt-get install build-essential
      native-keymap native node module dependencies:

      • Debian-based: sudo apt-get install libx11-dev libxkbfile-dev
      • Red Hat-based: sudo yum install libX11-devel.x86_64 libxkbfile-devel.x86_64 # or .i686
      • FreeBSD: sudo pkg install libX11
        keytar native node module dependencies (reference):

        • Debian/Ubuntu: sudo apt-get install libsecret-1-dev
        • Red Hat-based: sudo yum install libsecret-devel
        • Arch Linux: sudo pacman -S libsecret
        • Alpine: apk add libsecret-dev
    • Linux/MacOS

      • nvm is recommended to easily switch between Node.js versions.
    • Windows

      • windows-build-tools

        • run PowerShell as Administrator and copy paste the following: npm --add-python-to-path install --global --production windows-build-tools .
      • If you run into problems with installing the required build tools, the node-gyp documentation offers a useful guide how to install the dependencies manually. The versions required for building Theia are:

        • Python 3.6 or higher
        • Visual Studio build tools 17
      • If you have multiple versions of either python or Visual Studio installed or if the tool is not found, you may adjust the used version via the npm config:

        • npm config set python /path/to/executable/python --global
        • npm config set msvs_version 2017 --global

    安装流程

    以下记录皆在 Ubuntu22 下完成。

    基础开发环境配置

    由于 ubuntu22 已经携带了 python3 就不需要另外安装配置了。

    安装 git

    sudo apt update
    sudo apt-get install git

    安装 nvm

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

    安装成功后安装 node 16 版本

    nvm install 16

    配置 NPM 镜像源

    npm config set registry https://registry.npmmirror.com

    设置成功后可以直接安装 yarn,默认安装的都是 1.x.x 版本的

    npm i -g yarn

    Linux 开发环境额外依赖安装

    根据以上官方给的信息,Ubuntu 下还要额外安装一些依赖才能正常使用。

    sudo apt update
    sudo apt-get install build-essential libx11-dev libxkbfile-dev libsecret-1-dev

    输入命令确认工具正常调用

    gcc --version
    make --version
    pkg-config --version

    安装项目依赖

    环境都安装成功之后在项目下用 yarn 安装依赖。

    git clone https://github.com/eclipse-theia/theia.git \ # 命令会默认下载最新版本 需要下载项目指定版本安装
      && cd theia \
      && yarn

    安装完成后会自动执行编译,会输出类似以下信息,没有报错即可。

     >  Lerna (powered by Nx)   Running target prepare for 5 projects:
    
        - @theia/cli
        - @theia/eslint-plugin
        - @theia/re-exports
        - @theia/core
        - @theia/electron
    
     ——————————————————————————————————————————
    
    > @theia/re-exports:prepare
    
    yarn run v1.22.19
    $ tsc -b
    Done in 4.37s.
    
    > @theia/electron:prepare
    
    yarn run v1.22.19
    $ yarn -s generate-theia-re-exports
    Done in 1.63s.
    
    > @theia/core:prepare
    
    
    > @theia/cli:prepare
    
    yarn run v1.22.19
    yarn run v1.22.19
    $ tsc -b
    $ yarn -s generate-theia-re-exports
    Done in 1.49s.
    
    > @theia/eslint-plugin:prepare
    
    yarn run v1.22.19
    $ tsc -b
    Done in 25.37s.
    Done in 39.28s.

    启动示例

    启动浏览器示例:

    yarn download:plugins \
      && yarn browser build \
      && yarn browser start

    访问 http://localhost:3000 查看。

    启动 Electron 示例:

    yarn download:plugins \
        && yarn electron build \
        && yarn electron start

    安装问题记录

    基本都是官方提到的环境依赖不全导致

    • 安装编译环境

      sudo apt update
      sudo apt install build-essential

      命令执行后会安装 gcc 、g++ 、make 等软件包和必要的头文件库。

      安装完成后执行命令查看是否正常输出版本信息

      gcc --version
      make --version
    • PKG_CONFIG_PATH 环境变量未找到

      pkg-config 用来查找系统中安装库文件的信息,典型的是用作库的编译和连接。

      官网:PKG_CONFIG

      • 使用 apt-get 安装

        sudo apt-get update
        sudo apt-get install pkg-config
      • 使用 make 编译安装

        进入官网下载源码,进入目录后执行:

        make
        make check
        make install

        安装完成后执行命令查看是否正常输出版本信息

        pkg-config --version

        如果 --cflags 命令输出信息为空,会影响到 make 命令执行,可以配置环境变量

        export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
        export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1

        相关阅读:使用 pkg-config 让 C++ 工程编译配置更灵活

    • native-keymap 命令执行失败;No package 'x11' found;No package 'xkbfile' found

      sudo apt-get install libx11-dev libxkbfile-dev
    • keytar: Command failed. No package 'libsecret-1' found

      sudo apt-get install libsecret-1-dev
    • electron 下载过慢

      可以配置使用国内镜像地址:

      npm config set electron_mirror=https://npmmirror.com/mirrors/electron/

      或者始终设置跳过下载

      ELECTRON_SKIP_BINARY_DOWNLOAD=1
    • playwright、FFMPEG playwright 下载过慢

      pip 使用清华源:

      pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

      存放位置:

      %USERPROFILE%\AppData\Local\ms-playwright on Windows
      ~/Library/Caches/ms-playwright on MacOS
      ~/.cache/ms-playwright on Linux

      chromium 存放位置:~/.cache/ms-playwright/chromium-{版本号},目前安装下来的文件夹名是 chromium-1005

      ffmpeg 存放位置:~/.cache/ms-playwright/ffmpeg-{版本号},目前安装下来的文件夹名是 ffmpeg-1007

      也可以配置环境变量自定义文件位置:

      PLAYWRIGHT_BROWSERS_PATH={文件路径}/pw-browsers

      如果需要不下载二进制文件可以配置环境变量:

      PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

      然后再执行安装

    • 部分环境变量只想一次性生效或只在当前项目生效

      只生效一次可以加在执行命令前面,如

      ELECTRON_SKIP_BINARY_DOWNLOAD=1 yran

      只在当前项目生效,可以在项目根目录创建 .npmrc 文件,将配置信息写入:

      ELECTRON_SKIP_BINARY_DOWNLOAD=1
      PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
    • nvm 无法记忆切换的 Node 版本

      nvm-windowsnvm 实际上是两个工具,切换版本的命令不太一样。

      nvm-windows 使用 nvm use 能够切换默认版本,nvm 使用以下命令设置 nvm 默认版本

      nvm alias default 16.19.1

LnEoi
665 声望15 粉丝