https://github.com/morlay/modularify
https://github.com/morlay/modularify
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/morlay/modularify
- Owner: morlay
- Created: 2015-12-16T08:36:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-17T06:54:16.000Z (over 10 years ago)
- Last Synced: 2025-10-05T19:59:13.748Z (8 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## modularify
[](https://travis-ci.org/morlay/modularify)
[](https://npmjs.org/package/modularify)
[](https://david-dm.org/morlay/modularify)
[](https://npmjs.org/package/modularify)
`global is eval` so this tool will transform window assignment to commonjs way
from
```js
(function(win){
var Button = 1;
document;
window['Button'] = Button;
})(window)
```
to
```js
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](https://babeljs.io/docs/usage/options/);
```js
import * as modularify from 'modularify'; // babel 6 issue
const opts = {
plugins: [
modularify.removeRootCallExpression,
[modularify.removeCallExpression, {
callers: [
'componentHandler'
]
}]
[modularify.assignGlobalsWithRequire, {
globals: {
window: 'global',
document: 'global/document'
}
}],
[modularify.exportsReplace, {
exports: {
window: 'exports'
}
}]
]
}
modularify.transform('', opts);
```