Create Command

The create command is responsible for setting up a new browser extension project using Extension.js. This command accepts flags like --template for initializing your extension with various templates, and allows you to define the directory or path where the extension will be created. The command is designed to simplify the setup process for developers, providing a streamlined way to get started with cross-browser extension development.

Usage

You can run the create command using the following syntax. Replace <extension-name|extension-path> with your project name or path and set any required options:

npm
pnpm
yarn
npx extension@latest create <extension-name|extension-path> [options]

Example Usage with Templates

npm
pnpm
yarn
npx extension@latest create my-extension --template=react

This example demonstrates creating a new extension using the react template. You can substitute react with any available template from the Templates section.

Path Option

The create command can also accept a specific directory where you want to create the extension. If no path is provided, it defaults to the current working directory.

npm
pnpm
yarn
npx extension@latest create path/to/my-extension --template=react

In this example, the extension is created in the path/to/my-extension directory.

Arguments and Flags

The create command accepts several arguments and flags to customize the behavior of the extension creation:

Flag Argument What it does Defaults to
[path or name] The extension path or name If a path is defined, loads the local extension. If a name is provided, loads the extension in the current working directory. process.cwd()
-t, --template Name of the template used to bootstrap your extension Bootstrap your extension using a template new
  • Path or Name: If a path is provided, the extension is created at that location. If a name is provided, it is created in the current working directory.
  • --template: Specifies the template to use when bootstrapping the extension (e.g., react, typescript).

Example Commands

This command creates a new extension named my-new-extension using the React template.

npm
pnpm
yarn
npx extension@latest create my-extension --template=react

Available Templates

Users can choose from a variety of templates when creating their extension projects, including:

  • React: For building new tab or content scripts using React.
  • TypeScript: Initializes an extension with TypeScript support.
  • Custom: You can also specify external templates by providing a URL to a GitHub repo or any npm package.

Best Practices

  • Use meaningful names: When naming your extension or path, use meaningful names that reflect the project's purpose.
  • Customizing Templates: You can always customize your extension after it's created. For example, if you want to add TypeScript support to a React template, it's easy to do so afterward.
  • Starting from a Template: Using a template is the fastest way to get started with browser extension development in Extension.js.

Next Steps

Once your extension is created, you can start developing by running extension dev. For more details on development workflows, check out the Development Guide.