Nonconformist Propaganda Machine

npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

This package has been deprecated

Author message:

I wrote this library for fun. Now I don't maintain this library anymore. I don't think you will need this library

rollup-plugin-multi-var

1.0.2 • Public • Published

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;

install

npm i rollup-plugin-multi-var

Downloadsweekly downloads

3

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability