0.0.8 • Published 5 years ago

rollup-plugin-import-from-scope v0.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

rollup-plugin-import-from-scope

Greenkeeper badge Build Status Build status codecov

  1. import {String, Number, Error, ...} from 'global' allows you to manage usage of global variables.
  2. JavaScript minifier works well because global variables are bind to local variables that can be renamed by minifier.

Installation

npm install --save-dev rollup-plugin-import-from-scope

Usage

// rollup.config.js
const importFromScope = require('rollup-plugin-import-from-scope');
{
  ...
  plugins: [
    importFromScope(),
  ],
  ...
}

How it works

This plugin detects imports from global and generates an intermediate file that exports required global objects.

Suppose that you have following code:

// your-script.js
import {console, document} from 'global';
console.log(document.title);

This plugin generates the following intermediate files:

// __intermediate__/your-script.js
import _0 from '__intermediate__/console';
export {_0 as console};
import _1 from '__intermediate__/document';
export {_1 as document};
// __intermediate__/console
export default self['console'];
// __intermediate__/document
export default self['document'];

Options

  • globalVariable (default: self): The name of the global variable.
  • moduleNames: An object which has following properties.
  • moduleNames.static (global)
  • moduleNames.getter (getglobal)
  • moduleNames.setter (setglobal)
  • acorn: An object which passed to acorn.

Assume you use the following options:

importFromScope({
  globalVariable: 'GLOBAL',
  moduleNames: {
    static: 'G',
    getter: 'getG',
    setter: 'setG',
  },
})
  • import {x} from 'G'const x = GLOBAL.x
  • import {x} from 'getG'const x = () => GLOBAL.x
  • import {x} from 'setG'const x = (value) => GLOBAL.x = value

LICENSE

MIT

0.0.8

5 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago