Skip to main content

Setup & requirements

Packemon has been designed to build and prepare packages for distribution, and as such, supports workspaces (monorepos) or single packages (polyrepo). By default, only packages configured for Packemon will be built (denoted by a packemon block in package.json). This allows specific packages to be completely ignored if need be.

To ease the setup process, Packemon provides an interactive init command that will configure each package one-by-one. This must be ran in the project root.

packemon init

Package structure#

Regardless of your project type, Packemon makes the following assumptions, some of which are hard requirements.

  • Each package must contain a package.json (of course).
  • Each package must have a source folder named src. Builds will output relative to this.
  • Each package must have a source entry point, typically a src/index.(js|ts) file.
  • Each package may contain a tsconfig.json.
  • Each package should contain a LICENSE(.md)? and README(.md)?.

This would look something like the following.

/โ”œโ”€โ”€ src/โ”œโ”€โ”€ package.jsonโ”œโ”€โ”€ LICENSEโ””โ”€โ”€ README.md

Babel integration#

Transforming generators#

If you are using generators and are targeting the browser platform with an old supported version, you will need to include the @babel/runtime dependency in your project. This is because generators are compiled to regenerator-runtime (more info).

yarn add @babel/runtime

TypeScript integration#

Integrating with TypeScript can sometimes be tricky, and with Packemon, that is definitely the case. Since Packemon now handles the build process, TypeScript should be configured for type checking and declaration generation only.

However, if that is not possible. You can supply a custom tsconfig for Packemon building only through the --declarationConfig option.

Update output directories#

Both the outDir and declarationDir settings should be updated to dts, and should not be set to lib, build, or some other variant. This is especially true if using project references.

tsconfig.json
{    "compilerOptions": {        "declaration": true,        "declarationDir": "dts",        "outDir": "dts"    }}

Enable emitting#

The noEmit setting should only be used on the command line (via an npm script) and should not be configured explicitly. We require emitting of declarations.

tsconfig.json
{  "compilerOptions": {-    "noEmit": false  }}

Disable JSON resolving#

The resolveJsonModule setting alters the output folder structure in such a way that it breaks the guarantees that Packemon needs for handling declarations.

tsconfig.json
{    "compilerOptions": {        "resolveJsonModule": false    }}

If you really need to support this feature, please create an issue so that we can track it properly.

Supporting project references#

Alongside the requirements listed above, the tsconfig.json within each project reference package should be updated to only emit declarations to dts, like so.

tsconfig.json
{    "compilerOptions": {        "declaration": true,        "declarationDir": "dts",        "outDir": "dts",        "rootDir": "src",        "emitDeclarationOnly": true    }}