---
title: Installation
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Despite all the recent advancements in the npm ecosystem, setting up a TypeScript (or JavaScript)
package is still quite tedious and non-trivial. Packemon hopes to alleviate this problem, and can be
integrated into [existing projects](#add-to-an-existing-project), or used to
[scaffold a new project](#scaffold-a-new-project).

## Scaffold a new project

Starting from scratch? Let Packemon scaffold the entire project structure for you! Run the
[`packemon scaffold`](./scaffold) command below, select a template, answers some questions, and let
Packemon work its magic. View the scaffold docs for more information on our supported templates.

<Tabs
  groupId="package-manager"
  defaultValue="yarn"
  values={[
    { label: 'Yarn 2+', value: 'yarn2' },
    { label: 'Yarn 1', value: 'yarn' },
    { label: 'npm', value: 'npm' },
  ]}
>
  <TabItem value="yarn2">

```bash
yarn dlx packemon scaffold ./mylib
```

  </TabItem>
  <TabItem value="yarn">

```bash
npx packemon scaffold ./mylib
```

  </TabItem>
  <TabItem value="npm">

```bash
npx packemon scaffold --packageManager npm ./mylib
```

  </TabItem>
</Tabs>

Scaffolding a new project will...

- Align with the [defined file structure](./setup.mdx#package-structure).
- Create config files for common developer tools (Babel, ESLint, Vitest, TypeScript, etc), based on
  [moonrepo presets](https://github.com/moonrepo/dev).
- Create package specific files like `package.json`, readme's, and licenses.
- Create example source and test files.
- Install dependencies with the chosen package manager.

## Add to an existing project

To add Packemon to an existing project, install `packemon` as either a development or global
dependency. Once installed, you will need to [configure each package](./config) by running the
[`packemon init`](./init) command. Be sure your project abides the [defined requirements](./setup)!

<Tabs
  groupId="package-manager"
  defaultValue="yarn"
  values={[
    { label: 'Yarn', value: 'yarn' },
    { label: 'npm', value: 'npm' },
  ]}
>
  <TabItem value="yarn">

```bash
yarn add --dev packemon
yarn packemon init
```

  </TabItem>
  <TabItem value="npm">

```bash
npm install --save-dev packemon
npx packemon init
```

  </TabItem>
</Tabs>

Furthermore, you can now reference the `packemon` binary within a `package.json` script. We suggest
the following `build` (for development) and `pack` (for production) scripts.

```json title="package.json"
{
  "name": "package",
  "scripts": {
    "build": "packemon build",
    "pack": "packemon pack --addEngines --addFiles --declaration"
  }
}
```

## Configure Babel

Packemon relies on its own internal Babel configuration for building packages, but if you want to
use the same configuration for local development and testing, update your root `babel.config.js` to
the following.

```js title="babel.config.js"
const { createRootConfig } = require('packemon/babel');

module.exports = createRootConfig();
```

If you're using workspaces and certain packages require additional configuration that the root does
not provide (for example the React preset), you can
[create branch relative `.packemon.js` config](./advanced#customizing-babel-swc-and-rollup).
