Extra Conditions

Configure custom export conditions in package.json validation

Extra Conditions Example

This example demonstrates how to use the extraConditions option in package.json validation to allow custom export conditions.

Configuration

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

export default defineConfig({
    transformer,
    entries: [
        {
            input: "src/index.ts",
        },
    ],
    validation: {
        packageJson: {
            extraConditions: ["custom-bundler", "my-framework", "special-env"]
        }
    }
})

Package.json Example

{
    "name": "my-package",
    "exports": {
        ".": {
            "custom-bundler": "./dist/custom.js",
            "my-framework": "./dist/framework.js",
            "special-env": "./dist/special.js",
            "import": "./dist/index.mjs",
            "require": "./dist/index.cjs",
            "default": "./dist/index.js"
        }
    }
}

What this does

  • Without extraConditions: Packem would warn about unknown conditions custom-bundler, my-framework, and special-env
  • With extraConditions: These custom conditions are recognized as valid and no warnings are generated
  • Unknown conditions not listed in extraConditions will still generate warnings

Use Cases

  • Custom bundler-specific conditions
  • Framework-specific export conditions
  • Environment-specific conditions
  • Tool-specific conditions
  • Any custom export condition your package needs to support

Standard Conditions

Packem already recognizes these standard and community conditions without needing to add them to extraConditions:

Standard Node.js Conditions

  • import - ES modules
  • require - CommonJS
  • node - Node.js environment
  • default - Fallback condition

Community Conditions

  • browser - Browser environment
  • development - Development builds
  • production - Production builds
  • types - TypeScript declarations
  • react-native - React Native platform
  • react-server - React Server Components
  • edge-light - Edge runtime environments
  • Package.json Validation - Complete package.json validation setup
  • Bundle Size Limits - Configure bundle size validation
  • Multi-Runtime Exports - Target multiple runtimes with conditional exports
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