API Reference

Programmatic API, plugin development, hooks, and package documentation for Packem

API Reference

Use Packem programmatically, write custom plugins, or hook into the build lifecycle. This section covers the public API for every package in the Packem ecosystem.

Packages

PackageDescriptionDocs
@visulima/packemBundler core, CLI, and configuration API
@visulima/packem-rollupRollup plugins and transformer integrationsAPI
@visulima/rollup-plugin-cssCSS processing and optimization plugin
@visulima/css-style-injectRuntime CSS injection utility
@visulima/packem-shareShared types, utilities, and constants

Programmatic usage

Run Packem from your own scripts instead of the CLI:

import { build } from '@visulima/packem'

await build({
  root: process.cwd(),
  config: 'packem.config.ts',
})

Plugin development

Packem uses Rollup under the hood, so any Rollup plugin works. Wrap yours in a function and add it to the plugins array:

import { defineConfig } from '@visulima/packem/config'
import transformer from '@visulima/packem/transformer/esbuild'

export default defineConfig({
  transformer,
  rollup: {
    plugins: [myCustomPlugin()],
  },
})

See the plugins option for configuration details.

Specialized APIs

Build hooks

Hook into the build lifecycle to run custom logic:

export default defineConfig({
  hooks: {
    'build:before': (context) => {
      console.log('Build starting...')
    },
    'build:done': (context) => {
      console.log(`Built in ${context.duration}ms`)
    },
  },
})

See the hooks option for the full list of available hooks.

Environment variables

VariableDescription
PACKEM_CONFIGPath to config file (overrides auto-detection)
NODE_ENVSet to production for optimized builds
DEBUGSet to packem:* for debug output
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues