MCPcopy Index your code
hub / github.com/danielroe/rollup-plugin-pure

github.com/danielroe/rollup-plugin-pure @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
15 symbols 50 edges 10 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rollup-plugin-pure

npm version npm downloads Github Actions Codecov

Automatically add /* #__PURE__ */ annotations before definition functions

Features

  • ⚡️ avoids end-users bundling unused code

How it works

Definition functions (for example, in Vue with defineComponent) are increasingly common but do not play nice with tree-shaking. It's not possible to tell whether or not a function call which receives an object can be tree-shaken from a build, as it's possible there might be side effects.

Rollup supports /* @__PURE__ */ annotations to declare this from a library author's point of view, but it can be tricky when we know that every occurrence of a function call is pure.

This plugin will automatically inject the annotation before any occurrence of the function call, as well as injecting /* @__NO_SIDE_EFFECTS__ */ annotations in front of function declarations.

Installation

Install and add rollup-plugin-pure to your Vite or Rollup config.

pnpm add -D rollup-plugin-pure
import { PluginPure } from 'rollup-plugin-pure'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    PluginPure({
      functions: ['defineComponent', /^define(Page|Meta)$/],
      include: [/(?<!im)pure\.js$/],
      // exclude: [],
      // sourcemap: true,
    }),
  ],
})

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Stub module with pnpm dev:prepare
  • Run pnpm dev to start playground in development mode

License

Made with ❤️

Published under the MIT License.

Extension points exported contracts — how you extend this code

PureAnnotationsOptions (Interface)
(no doc)
src/index.ts

Core symbols most depended-on inside this repo

$createConfig
called by 4
playground/src/pure.js
withLocations
called by 3
src/index.ts
defineComponent
called by 3
playground/src/pure.js
definePage
called by 3
playground/src/pure.js
PluginPure
called by 2
src/index.ts
isMatched
called by 2
src/index.ts
transform
called by 1
test/plugin.bench.ts
hashStyleFunction
called by 1
playground/src/pure.js

Shape

Function 14
Interface 1

Languages

TypeScript100%

Modules by API surface

src/index.ts7 symbols
playground/src/pure.js4 symbols
playground/src/impure.js3 symbols
test/plugin.bench.ts1 symbols

For agents

$ claude mcp add rollup-plugin-pure \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page