Vite

This document provides instructions for working with Vite and the CommandK CLI. It explains how to run your Vite application and manage secrets effectively using the CommandK CLI.

Prerequisites

Before you begin the integration process, make sure you have the following:

  1. API Access Token: To authenticate your Vite application with CommandK, you'll need an API access token. If you haven't obtained one yet, refer to this link for instructions on how to acquire it.

Integration Steps

Follow these steps to integrate CommandK with your Vite application:

Step 1: Create a Vite Application

If you haven't already created a Vite application, you can set up a new project using the Vite CLI or any other preferred method. Here, we'll use the Vite CLI for demonstration:

  1. Install the Vite CLI globally if you haven't already:

    npm install -g create-vite
    
  2. Create a new Vite project using the following command:

    create-vite my-vite-app
    

    Replace my-vite-app with your desired project name.

  3. Follow the prompts to configure your Vite project. You can choose options such as the project template (Vue, React, etc.), package manager, and more based on your project requirements.

Step 2: Access Secrets in Your Vite Application

Inside your Vite application, you can access secrets as environment variables. Open your Vite configuration file (usually vite.config.js) and add the following code snippet:

export default {
  // Other Vite configuration options...

  define: {
    'process.env.COMMANDK_SECRET_KEY': process.env.COMMANDK_SECRET_KEY,
  },
};

In this code, 'process.env.COMMANDK_SECRET_KEY' is the environment variable that will store your secret.

Running Your Vite Application

To run your Vite application with the CommandK CLI, you can use the following command:

$ cmdk run <application-name> --environment development -- npm run dev

Replace <application-name> with the actual name of your Vite application. This command will execute your Vite application in the development environment.

Running with dotenv

If your Vite application uses dotenv to manage environment variables, you can utilize the CommandK CLI to write these variables to a .env.development file and then run your service. Follow these steps:

  1. Execute the following command:
$ cmdk run <application-name> --environment development \
     --run-type file-store \
     --file-name .env.development.local \
     --file-format env \
     -- npm run dev

Replace <application-name> with the actual name of your Vite application. This command will write your environment variables to the .env.development.local file in the specified env format and then run your Vite service.

Adjust the file name and format to match your project's configuration if necessary.

By following these instructions, you can seamlessly integrate the CommandK CLI with your Vite application, making it easy to manage secrets and run your application securely.