modularify

0.1.0 • Public • Published

modularify

Build Status NPM Dependencies License

global is eval so this tool will transform window assignment to commonjs way

from

(function(win){
  var Button = 1;
  document;
  window['Button'] = Button;
})(window)

to

var document = require('global/document');
var window = require('global');
 
var win = window;
var Button = 1;
document;
exports['Button'] = Button;

Options

Could work with babel and could pass babel options;

import * as modularify from 'modularify'; // babel 6 issue
 
const opts = {
  plugins: [
    modularify.removeRootCallExpression,
    [modularify.removeCallExpression, {
      rules: [
        'componentHandler'
      ]
    }]
    [modularify.assignGlobalsWithRequire, {
      globals: {
        window: 'global',
        document: 'global/document'
      }
    }],
    [modularify.exportsReplace, {
      exports: {
        window: 'exports'
      }
    }]
  ]
}
 
modularify.transform('<codeString>', opts);

Readme

Keywords

none

Package Sidebar

Install

npm i modularify

Weekly Downloads

2

Version

0.1.0

License

WTFPL

Last publish

Collaborators

  • morlay_null