Updated on 2024-11-21 GMT+08:00

Building with npm

Build Vue and Webpack projects with npm.

Build on GUI

Add Build with npm, when configuring build actions. Set the parameters according to Table 1.

Table 1 Parameters for building with npm

Parameter

Description

Action Name

Assign a custom name to the build action. The name can contain:

  • Letters, digits, hyphens (-), underscores (_), commas (,), semicolons (;), colons (:), periods (.), slashes (/), and parentheses.
  • 1 to 128 characters.

Tool Version

Select a tool version that matches your current development environment.

For tool versions supported by CodeArts Build, see build tools and versions. If the current tools and versions do not meet your requirements, you can customize a build environment.

Commands

Configure the npm commands, or use the default ones. If you have special build requirements, enter your custom build script in the text box. For more commands, see the Node.js official website.

Continue After Failure

Specify whether to proceed after the current action fails by setting the parameter to either Yes or No.

Build with Code

Modify the code in the BUILD block in Creating a YAML File for Your Code-based Build by referring to the following sample code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
version: 2.0 # The value must be 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
         ignore_fail: true
Table 2 Parameters in the sample code

Parameter

Type

Description

image

String

The image address can be in either of the following formats:

  • Use cloudbuild@nodejs8.11.2. This address starts with cloudbuild and uses the at sign (@) as a separator, with the default image version provided by CodeArts Build following it.
  • Use a complete SWR image path, for example, swr.example.example.com/codeci_test/demo:141d26c455abd6d7xxxxxxxxxxxxxxxxxxxx.

command

String

Configure the npm commands. For more commands, see the Node.js official website.

ignore_fail

String

Whether to proceed after the current action fails.
  • true: Yes
  • Empty: No