Edit

Create and build a code component

This article shows how to create and build a code component by using Microsoft Power Platform CLI. Use these steps to set up a component project, install its dependencies, and build it so you can package and import it into Microsoft Dataverse.

Prerequisites

Install the following components:

  1. Visual Studio Code (VSCode) (Ensure you select the Add to PATH option)
  2. node.js (Use the LTS version)
  3. Microsoft Power Platform CLI (Use the Visual Studio Code extension)

Create a new code component project

Open Visual Studio Code and open a new terminal window by selecting Terminal > New Terminal.

  1. In the terminal window, create a new folder on your local machine, for example, C:\projects\My_code_Component by using the command mkdir <Specify the folder name>.

  2. Go to the newly created folder by using the command cd <specify your new folder path>.

  3. Create a new component project by using the pac pcf init command. This example creates a field component named SampleComponent in the Contoso namespace:

    pac pcf init --namespace Contoso --name SampleComponent --template field --run-npm-install
    
  4. The preceding command also runs the npm install command to retrieve all the required project dependencies.

  5. Open your project folder C:\projects\My_code_Component in any developer environment of your choice and get started with your code component development. The quickest way to get started is by running code . from your command prompt once you are in the C:\projects\My_code_Component directory. This command opens your component project in Visual Studio Code.

  6. Implement the required artifacts for the component like manifest, component logic, and styling and then build the component project. For more information, see Create your first code component.

Build your code component

To build the component project, open the project folder that contains package.json in Visual Studio Code. Use the Ctrl+Shift+B command, and then select the build options.

Alternatively, you can quickly build the component by using the npm run build command in the Visual Studio Code terminal window for development purposes. For building a release version, use npm run build -- --buildMode production.

Tip

To debug the component during or after the build operation, see Debug a code component.

When you finish implementing the component logic in TypeScript, bundle all the code component elements into a solution file. You can import this solution file into Microsoft Dataverse. For more information, see Package a code component.

See also

Debug code components
Package a code component
Add code components to a column or table
Power Apps component framework API reference
Power Apps component framework overview