Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/MithrilJS/mopt

Babel plugin to optimize Mithril m() calls into simple JS objects for speed
https://github.com/MithrilJS/mopt

babel build mithril optimization

Last synced: 3 months ago
JSON representation

Babel plugin to optimize Mithril m() calls into simple JS objects for speed

Awesome Lists containing this project

README

        

mopt [![NPM Version](https://img.shields.io/npm/v/mopt.svg)](https://www.npmjs.com/package/mopt) [![NPM License](https://img.shields.io/npm/l/mopt.svg)](https://www.npmjs.com/package/mopt)
=================














A [babel](babeljs.io) plugin to statically optimize [mithril](http://mithril.js.org) hyperscript function invocations.

```js
// This hyperscript function invocation
m(".fooga");

// Gets optimized into
m.vnode("div",undefined,{className:"fooga"},undefined,undefined,undefined);
```
Please file an issue if you come across any cases that this doesn't handle, I'd love to improve the number of structures I can rewrite!

## Mithril Version Warning

`mopt` **only** works with `[email protected]`.

For optimizing `[email protected]` see [mithril-objectify](https://npmjs.com/mithril-objectify).

## Installation

Install with npm

`npm i mopt`

## Usage with Babel

### `.babelrc`

```js
// .babelrc
{
"plugins": [ "mopt" ]
}
```

### CLI

`$ babel --plugins mopt script.js`

### API

```js
require("babel-core").transform("", {
plugins: [ "mopt" ]
});
```

## Usage with a bundler
### Rollup - [`rollup-plugin-babel`](https://www.npmjs.com/package/rollup-plugin-babel)
### Browserify - [`babelify`](https://www.npmjs.com/package/babelify)
### WebPack - [`babel-loader`](https://www.npmjs.com/package/babel-loader)