1.0.2 • Published 6 years ago

rollup-plugin-multi-var v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

rollup-plugin-multi-var

Declare multiple global variables from the named exports on the entry file.

Introduction

Some libraries may wish to export multiple names on the global object. However, due to limitation of Rollup, the library authors can only play some "cheat" by getting the global object using Function('return this') and manually declare the variables on the global object.

rollup-plugin-multi-var comes into rescue by trapping all the named export on the entry file and dynamically declares the variables on the global object.

Usage

rollup-plugin-multi-var doesn't require any configuration:

import multi from 'rollup-plugin-multi-var';

export default {
    plugins: [
        multi()
    ]
};

rollup-plugin-multi-var is able to trap all forms of named export, default export is ignored:

export { localName1 , localName2 as exportName2 };
export { exportName1 , exportName2 as alias2 } from 'some-module';
export * from 'some-module';
export let variable1, variable2;
export function functionName(){};
export class className{};

Under the hood

In:

const foo = 'bar',
      baz = 'qux';

export { foo , baz };
export * from './some-module.js';

Out:

var _this = typeof window == 'object' ? window : typeof self == 'object' ? self : Function('return this')();

const foo = 'bar',
      baz = 'qux';

export { foo , baz };
export * from './some-module.js';

import * as _package from './some-module.js';

for(var name in _package){
    _this[name] = _package[name];
}

_this.foo = foo;
_this.baz = baz;
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago