Skip to main content

Installation

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, or used to scaffold a new project.

For future referene, a project in the context of Packemon is either a package (polyrepo), or a collection of packages (monorepo). Choose the option that best suits your needs.

Scaffold a new project#

Starting from scratch? Let Packemon scaffold the entire project structure for you! Run the packemon 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.

npx packemon scaffold ./mylib

Scaffolding a new project will...

  • Align with the defined file structure.
  • Create config files for common developer tools (Babel, ESLint, Jest, TypeScript, etc), based on Beemo presets.
  • 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 by running the packemon init command. Be sure your project abides the defined requirements!

yarn add --dev packemonyarn packemon init

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.

package.json
{    "name": "package",    "scripts": {        "build": "packemon build",        "pack": "NODE_ENV=production packemon pack --addEngines --declaration=standard"    }}

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.

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 .babelrc.js configs. These configs must be located relative to the package's package.json.

.babelrc.js
const { createConfig } = require('packemon/babel');
module.exports = createConfig(__dirname); // Dir is required!

We suggest using the configuration as is, which means no custom plugins or presets.