https://github.com/mickeyjsx/babel-plugin-mickey-model-loader
💪 Inject a model loader function into mickey with hmr support.
https://github.com/mickeyjsx/babel-plugin-mickey-model-loader
babel framework hmr hmr-support mickey model plugin react redux saga
Last synced: about 2 months ago
JSON representation
💪 Inject a model loader function into mickey with hmr support.
- Host: GitHub
- URL: https://github.com/mickeyjsx/babel-plugin-mickey-model-loader
- Owner: mickeyjsx
- License: mit
- Created: 2017-08-30T07:13:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-14T09:50:55.000Z (over 5 years ago)
- Last Synced: 2024-04-26T06:52:59.722Z (about 1 year ago)
- Topics: babel, framework, hmr, hmr-support, mickey, model, plugin, react, redux, saga
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-plugin-mickey-model-loader
> Inject a model loader function into mickey with hmr support.
[](https://github.com/mickey/babel-plugin-mickey-model-loader/blob/master/LICENSE)
[](https://www.npmjs.com/package/babel-plugin-mickey-model-loader)
[](https://travis-ci.org/mickeyjsx/babel-plugin-mickey-model-loader)
[](https://david-dm.org/mickey/babel-plugin-mickey-model-loader)## Install
```
npm install babel-plugin-mickey-model-loader [email protected] --save-dev
```## Usage
Add the following section in your `.babelrc`:
```
{
"plugins": ["mickey-model-loader", { loaderOptions: { directory: './models' } }]
}
```Load models:
```
import React from 'react';
import createApp from 'mickey';
import SomeComponent from './SomeComponent';const app = createApp({
historyMode: 'hash',
});app.load(); // default load all models from './models'
app.render(, document.getElementById('root'));
```## app.load(pattern)
With this plugin, a handily method `load(pattern)` will be injected into `app`.
This method will try to load models matched with `pattern` from `loaderOptions.directory` specified directory (e.g. `./models`). The `pattern` is a glob pattern matched by [minimatch](https://www.npmjs.com/package/minimatch).
Falsely `pattern` will load all models.
## Options
- `disableHmr` Disable any HMR. Default: `false`
- `disableModelHmr` Disable model HMR. Default: `false`
- `quiet` Don't output any log. Default: `false`
- `loaderOptions` Options for `app.loader()` and these options are same as [`require.context(directory, useSubdirectories, regExp)`](https://webpack.github.io/docs/context.html#require-context)
- `directory` The directory to match within. Default: `'./models'`
- `useSubdirectories` A boolean flag to include or exclude subdirectories. Default: `true`
- `regExp` A regular expression to match files against. Default: `/^\.\//`Note: If `process.env.NODE_ENV` is `'production'`, will disable any HMR and do not output any log. This is useful for release building.
## Contributing
Pull requests and stars are highly welcome.
For bugs and feature requests, please [create an issue](https://github.com/mickey/babel-plugin-mickey-model-loader/issues/new).