[READ-ONLY] Mirror of https://github.com/danielroe/rollup-plugin-pure. Annotate functions as pure for Rollup
0

Configure Feed

Select the types of activity you want to include in your feed.

TypeScript 58.5%
JavaScript 27.1%
HTML 3.4%
Other 11.0%
618 11 7

Clone this repository

https://git.vm.fail/danielroe.dev/rollup-plugin-pure https://git.vm.fail/did:plc:sxookp5d26knimna63juv36j
ssh://git@knot1.tangled.sh:2222/danielroe.dev/rollup-plugin-pure ssh://git@knot1.tangled.sh:2222/did:plc:sxookp5d26knimna63juv36j

For self-hosted knots, clone URLs may differ based on your setup.


README.md

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.