Unbundle

Preserve file structure mode

Unbundle

The unbundle option switches Packem from bundling everything into a single file to preserving the original source file structure. Each module is emitted as its own output file, mirroring the directory layout of your source tree.

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

export default defineConfig({
  unbundle: true,
})

Default

unbundle defaults to false — Packem bundles your modules together.

What "preserved structure" means

With unbundle: true, instead of inlining imported modules into one output, every module becomes a separate file at a path that matches its source location. For example, if src/index.ts re-exports from ./a/indexA and ./b/indexB:

src/index.ts        →  dist/index.js
src/a/indexA.ts     →  dist/a/indexA.js
src/b/indexB.ts     →  dist/b/indexB.js

The import graph between those files is kept, so dist/index.js still imports from dist/a/indexA.js rather than containing its code.

This is the "preserve modules" style of output: useful when consumers want to import individual files, when you want maximal tree-shakeability for downstream bundlers, or when you need the output layout to mirror the source layout.

CLI flag

unbundle can also be enabled per build from the command line:

packem build --unbundle

The flag is described as "Enable unbundle mode to preserve source file structure instead of bundling into a single file".


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