
# Yarn构建
使用Yarn可以构建JavaScript工程。
- [图形化构建]
  在[配置构建步骤](https://support.huaweicloud.com/usermanual-codeci/codeci_ug_0059.html)中，添加"Yarn构建"构建步骤，可参考[表1]配置参数。
   表1Yarn构建参数说明 
  | **参数**    | **说明**                                                                                                                                                                                                                                                                                                                                                              |
  |:---|:---|
  | 步骤显示名称    | 构建步骤的名称，可自定义修改。 - 支持中文、英文、数字、"-"、"_"、英文逗号、英文分号、英文冒号、"."、"/"、圆括号（中英文）。  - 字符长度范围为1\~128。   |
  | 工具版本      | 根据用户实际开发环境的需要，选择对应的工具版本。 CodeArts Build支持的工具版本，可查看[构建工具版本](https://support.huaweicloud.com/productdesc-codeci/cloudbuild_07_0004.html)。若当前的工具版本不满足您的使用要求，您可以[制作镜像并推送到SWR仓库](https://support.huaweicloud.com/usermanual-codeci/codeci_ug_0013.html)。                                                                                |
  | 命令        | 配置Yarn命令，一般使用系统默认生成的命令即可。如有特殊构建要求，可以在文本域中输入自定义的构建脚本。更多命令使用方法可参考[Yarn官网](https://yarnpkg.com/)。                                                                                                                                                                                                                                                                      |
  | 失败后是否继续运行 | 当前步骤执行失败后是否继续执行下一个步骤，根据实际使用场景选择是或否。                                                                                                                                                                                                                                                                                                                                 |
     
- [代码化构建]
  参考以下代码示例，修改在[创建代码化构建使用的YAML文件](https://support.huaweicloud.com/usermanual-codeci/codeci_ug_0058.html#codeci_ug_0058__section72391847131511)中的BUILD部分代码信息。
  ```
  version: 2.0 # 必须是2.0
  steps:
    BUILD:
      - yarn:
         inputs:
            command: |-
  #nodejs 版本小于18时，可以设置下面的值 
                         npm config set cache-folder /yarncache
                         npm config set registry http://mirrors.tools.huawei.com/npm/
                         npm config set disturl http://mirrors.tools.huawei.com/nodejs
                         npm config set sass_binary_site http://mirrors.tools.huawei.com/node-sass/
                         npm config set phantomjs_cdnurl http://mirrors.tools.huawei.com/phantomjs
                         npm config set chromedriver_cdnurl http://mirrors.tools.huawei.com/chromedriver
                         npm config set operadriver_cdnurl http://mirrors.tools.huawei.com/operadriver
                         npm config set electron_mirror http://mirrors.tools.huawei.com/electron/
                         npm config set python_mirror http://mirrors.tools.huawei.com/python
                         
                         #nodejs 版本大于等于18时，可以设置下面的值 
                         #npm config set registry http://mirrors.tools.huawei.com/npm/ 
                         npm config set prefix '~/.npm-global'
                         export PATH=$PATH:~/.npm-global/bin
                         #yarn add node-sass-import --verbose
                         yarn install --verbose
                         yarn run build
                         tar -zcvf demo.tar.gz ./**
           ignore_fail: true
  ```
  表2代码示例参数说明 
  | **参数**      | **类型** | **说明**                                                                                                                                                                                                                                                                                                |
  |:---|:---|:---|
  | command     | string | 配置Yarn命令。更多命令使用方法可参考[Yarn官网](https://yarnpkg.com/)。                                                                                                                                                                                                                                                   |
  | ignore_fail | string | 用于控制当前步骤执行失败后是否继续执行下一个步骤。 - true：是。  - 为空：否。   |
     
