unplugin-pure
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

unplugin-pure

This is a fork of Daniel Roe’s rollup-plugin-pure

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.

Installation

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

pnpm add -D unplugin-pure

Vite/Rollup

import { defineConfig } from 'vite'
import { PluginPure } from 'unplugin-pure'

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

esbuild

import { esbuildPure } from 'unplugin-pure'

await esbuild.build({
  entryPoints: ['app.jsx'],
  plugins: [esbuildPure({ functions: ['defineComponent'] })],
  bundle: true,
  outfile: 'out.js',
})

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • 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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.012latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.012
0.1.117
0.1.00

Package Sidebar

Install

npm i unplugin-pure

Weekly Downloads

29

Version

0.2.0

License

MIT

Unpacked Size

14.3 kB

Total Files

9

Last publish

Collaborators

  • justin-schroeder