Build Your First Power Apps Code App

Power Apps Code Apps allows developers to bring custom React applications into the Power Platform, integrated with key Power Platform services like Dataverse, connectors, and Entra ID authentication.
This article takes you through the basics of creating your first code app, step-by-step!
The Plan
We will follow an incremental 6-step plan to get you up and running with your first code app. While AI tools like GitHub Copilot and others have shown incredible capabilities in handling the entire end-to-end process (or at least a good chunk of it), we will walk through each, step by step so you understand what is going on in each step.
Install Dependencies
First, you must install several dependencies onto your machine:
- VS Code(or any IDE of your choice!)
- https://code.visualstudio.com/download
- NodeJS
- JavaScript runtime, required for developing React apps
- https://nodejs.org/en
- Power Platform PAC CLI
- Required to eventually “push” the Code App to your Environment
- https://learn.microsoft.com/en-us/power-platform/developer/howto/install-cli-msi
- This tutorial assumes you have already authenticated into your PAC CLI. See how to here via the
pac authcommand if you have not done so already.
- GitHub Copilot
- Within VS Code (as extension) or GitHub Copilot CLI
- You don’t necessarily need this to make a Code App… as long as you are a good React dev
- https://code.visualstudio.com/docs/copilot/overview
Enable Code Apps in your Environment
Before we begin building apps, it is important to note that as of the time of this writing you have to enable code apps in your target Power Platform environment. For whatever environment you wanted to host your first Code App in, visit the PPAC and find the "Power Apps Code Apps" toggle in the environment's settings!
Create a React App
We are now ready for the first step in app creation: make a React app! Run npm create vite@latest Cat-Facts in your terminal to scaffold a "boilerplate" React app.

After you do so, you should see it instantly serve the app for you on localhost. It provides a URL for you to navigate to in a browser to see your app.

Use AI to Customize your React App
With a basic React app now scaffolded, we can now proceed to build a React app that actually does something for us! If you are a talented React developer, you can certainly get to work writing your code at this stage. But for people like me that aren't familiar React code, you can use AI to assist with development. Below I'm running copilot in the terminal to open GitHub Copilot to assist with writing my app.

Once GitHub Copilot loads, I am running a simple prompt like the following:
Make me a “Random Cat Facts” app. When a user clicks on a button, they are shown a random cat fact.

And allowing it to do its thing, it confirms it is complete!

Next, run npm run dev in the terminal to test out your new React app!

Vite will now serve the React app to you on a local server for you to navigate to in the browser to test.

Prepare your React App to be a Power Apps Code App
Congrats, you have made your first React app! But the React app is not ready to be a Power Apps Code App just yet. To integrate the React app with Power Platform services (and allow it to be hosted as a Power Apps Code App), there are a few remaining steps:
First, install two packages in your React app from npm:
- Add the @microsoft/power-apps npm package to the project by running
npm install @microsoft/power-appsin your terminal. - Add the @microsoft/power-apps-vite npm package to the project by running
npm install @microsoft/power-apps-vitein your terminal.

After both packages install, add the following highlighted portions to your vite.config.ts file in your app (see screenshot). For reference, I've included the entire contents of my file after the changes below (you can just replace your entire vite.config.ts file with this).
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { powerApps } from "@microsoft/power-apps-vite/plugin"
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), powerApps()],
});

And then run pac code init -n "Fun Cat Facts" in your terminal to set up the app's power.config.json file with Power Apps-related information about the app.

Great! Your React app is now a Code App! Run npm run dev again to test it out. This time, you will see there is also a Power Apps "Local Play" URL. You can navigate to this URL in your browser to test out your code app as a Power Apps Code App!

Push to your Environment
After testing locally, run npm run build followed by pac code push to push your code app to your target Power Platform environment!

The PAC CLI will confirm it pushed successfully and provide a URL that you can navigate to to play it.

Connect with Dataverse
Ok - this Cat Facts app is fun, but how do we make it real? How can we, for example, connect our app to Dataverse and perform Create, Read, Update, Delete (CRUD) operations on it?
Run pac code add-data-source –a dataverse –t contact to connect your app with the Contacts Dataverse Table.

You will see running this command will add schema and service files to your app that allow the app to interface with the data in the Contacts table.

Microsoft provides terrific documentation on how code in your Code App can be written to interface with data in the Contacts table. See here if interested in reviewing yourself: How to: Connect your code app to Dataverse

Since I'll be relying on GitHub Copilot to write my app's code for me, I'll make sure to provide this documentation to the AI before instructing it to make my app for me. By explicitly providing this documentation, I am ensuring GitHub Copilot has the latest documentation and best practices to follow.
Provide the following prompt to GitHub Copilot:
First, read this documentation on how to interface with
Dataverse: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/connect-to-dataverse
I have already added the Contact table to this app.
Please make another page of this app in which it allows a user to Create, Read, Update, Delete records in the Contact table

Again, after allowing GitHub Copilot to do its thing for several minutes, it confirms it has completed the work!

Next step is to test out the app: run npm run dev and Vite will serve up your app locally. Navigate to the Power Apps "Local Play" URL in your browser.

Your app should be updated with an additional page that allows you to interface with data in your Contacts table.

Push to your Environment
And, just like last time, we are ready to push our app to our Power Platform environment!
Run npm run build followed by pac code push to push your Code App to your target Power Platform environment.


Additional Resources
Author
Written by Tim Hanewich, Sr. Solution Engineer at Microsoft