乐趣区

关于前端:Theia-开发环境搭建

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 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 默认版本

    nvm alias default 16.19.1
退出移动版