更新时间:2024-07-26 GMT+08:00
分享

使用Npm构建

使用Npm工具管理软件包,可以完成vue和webpack的构建。

图形化构建

配置构建步骤中,添加“Npm构建”构建步骤,可参考表1配置参数。

表1 Npm构建参数说明

参数名称

参数说明

是否必填

步骤显示名称

构建步骤的名称,可自定义修改。

  • 支持中文、英文、数字、“-”“_”、英文逗号、英文分号、英文冒号、“.”“/”、圆括号(中英文)。
  • 字符长度范围为1~128。

工具版本

根据用户实际开发环境的需要,选择对应的工具版本。

CodeArts Build支持的工具版本,可查看构建工具版本。若当前的工具版本不满足您的使用要求,您可以自定义构建环境

命令

配置Npm命令,一般使用系统默认生成的命令即可。如有特殊构建要求,可以在文本域中输入自定义的构建脚本。更多命令使用方法可参考Node.js官网

代码化构建

参考以下代码示例,修改在创建代码化构建使用的YAML文件中的BUILD部分代码信息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
version: 2.0 # 必须是2.0
steps:
  BUILD:
    - npm:
        image: cloudbuild@nodejs8.11.2
        inputs: 
          command: |
              export PATH=$PATH:~/.npm-global/bin
              npm config set registry https://repo.example.com/repository/npm/
              npm config set disturl https://repo.example.com/nodejs
              npm config set sass_binary_site https://repo.example.com/node-sass/
              npm config set phantomjs_cdnurl https://repo.example.com/phantomjs
              npm config set chromedriver_cdnurl https://repo.example.com/chromedriver
              npm config set operadriver_cdnurl https://repo.example.com/operadriver
              npm config set electron_mirror https://repo.example.com/electron/
              npm config set python_mirror https://repo.example.com/python
              npm config set prefix '~/.npm-global'
              npm install --verbose
              npm run build
表2 代码示例参数说明

参数名

参数类型

参数说明

是否必填

默认值

image

string

镜像地址,有以下两种格式。

  • cloudbuild@nodejs8.11.2:以cloudbuild开始,@作为分隔符,后面是CodeArts Build提供的默认镜像版本。
  • 完整的swr镜像地址,例如:swr.example.example.com/codeci_test/demo:141d26c455abd6d7xxxxxxxxxxxxxxxxxxxx

command

string

配置Npm命令。更多命令使用方法可参考Node.js官网

相关文档