This monorepo demonstrates a pattern for creating "split brain" functionality in JavaScript/TypeScript applications, where code can be handled differently depending on the build/execution context.
The demo showcases how a utility function (defineThings) can have different behaviors:
- Development/Authoring: In source code, developers can use the function without running a transform
- Production/Runtime: The
defineThingsfunction is completely removed (no-op) via a Babel plugin for optimized builds - Analysis/Preprocessing: The function implementation can be replaced to extract metadata from the options
- mylib: Core library providing the
defineThingsutility function - babel-plugin: Babel transformation that removes
defineThingscalls at build time - preprocessor: Tool that uses path aliasing to extract configuration from
defineThingscalls - example: Demonstration of how to use the pattern in a TypeScript project
This pattern is useful for:
- Stripping development-only code from production builds
- Extracting configuration/metadata from code without executing it
- Creating compile-time optimizations while preserving developer ergonomics
- Enabling tooling to analyze application structure without runtime overhead
See the individual package READMEs for details on how each component works.