rollup-plugin-multi-var

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

I wrote this library for fun. Now I don't maintain this library anymore. I don't think you will need this library
Last updated a year ago by wisgh .
MIT · Original npm · Tarball · package.json
$ cnpm install rollup-plugin-multi-var 
SYNC missed versions from official npm registry.

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;

Current Tags

  • 1.0.2                                ...           latest (a year ago)

3 Versions

  • 1.0.2 [deprecated]           ...           a year ago
  • 1.0.1 [deprecated]           ...           a year ago
  • 1.0.0 [deprecated]           ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 3
This Month 4
Last Day 0
Last Week 1
Last Month 1
Dependencies (3)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |