rollup-plugin-reassign
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Rollup reassign plugin Node.js Package

A rollup plugin for self reassign variable.

Install

npm i rollup-plugin-reassign -D

Config

import { reassign } from "rollup-plugin-reassign"

// See: https://github.com/rollup/plugins/blob/master/packages/pluginutils/README.md#createfilter
type FilterPattern = String | RegExp | Array[...String|RegExp]

interface ReassignOptions {
  include?: FilterPattern; // Include files
  exclude?: FilterPattern; // Eclude files
  sourcemap?: boolean; // Sourcemap default: true
  targetFns: {
    // Specify package
    [index: string]: {
      // Specify reassign function name and insert position (Nature number). if position === -1, it will be inserted end of params.
      [index: string]: number;
    };
  };
}

export default {
    plugins: [reassign(opt as ReassignOptions)]
}

Example

rollup.config.js

import { reassign } from "rollup-plugin-reassign";

export default {
  plugins: [
    reassign({
      targetFns: {
        "a-package": {
          default: 1,
          fn1: 1,
          fn2: 1,
          fn3: -1,
        },
      },
    }),
  ],
};

// `default` is `export default` variable, see `fn0` below

Code

import fn0, { fn1, fn2, fn3 } from "a-package";

let [k, setK] = fn0("a");
let { b } = fn1("a");
let a = fn2("a");
let c = fn2();
let d = fn3();

Compile to

import fn0, { fn1, fn2, fn3 } from "a-package";

let [k, setK] = fn0("a", ([$0, $1]) => (k = $0; setK = $1));
let { b } = fn1("a", ({ b: $0 }) => {
  b = $0;
});
let a = fn2("a", $ => a = $);
let c = fn2(undefined, $ => c = $);
let d = fn3($ => d = $)

License

MIT @anuoua

Readme

Keywords

Package Sidebar

Install

npm i rollup-plugin-reassign

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

86.2 kB

Total Files

12

Last publish

Collaborators

  • anuoua