Pure Annotations
What you'll learn: How to use /*#__PURE__*/ comments to tell bundlers that certain function calls are side-effect-free and safe to remove during tree shaking.
The Problem with Function Calls
Even when you've configured the sideEffects field in your package.json, bundlers sometimes struggle with function calls. Why? Because a bundler can't always prove that calling a function won't modify global state, perform I/O, or trigger other side effects. To be safe, it keeps those calls—even if the result is never used.
What Are Pure Annotations?
A pure annotation is a special comment (/*#__PURE__*/) placed directly before a function call. It tells the bundler: "Trust me, this function call has no side effects. If you're not using the result, feel free to delete it."
// Without annotation - bundler must keep this
const config = createConfig();
// With annotation - bundler can remove if unused
const config = /*#__PURE__*/ createConfig();
When to Use Them
Use pure annotations when:
- Your function is genuinely pure (no side effects)
- The bundler is being conservative and keeping code you know is safe to remove
- You're writing library code and want to give consumers better tree-shaking
Important: Only mark truly pure functions. If createConfig() actually logs to console, modifies globals, or performs I/O, the annotation would cause bugs.
Practical Impact
This is especially common in libraries that use helper functions or factory patterns. A single /*#__PURE__*/ annotation can eliminate entire chunks of unused initialization code from production bundles.
Key Takeaway: Pure annotations (/*#__PURE__*/) are a contract between you and your bundler—you promise a function call is side-effect-free, enabling aggressive dead code elimination even when static analysis can't prove it.