modularify

v0.0.4
global is eval

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);

Metadata

  • WTFPL
  • Whatever
  • Unknown
  • released 12/16/2015

Downloads

Maintainers