Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/jtsang4/umi-plugin-externals

📤 A umi plugin to help you make local built JS module as webpack external bundle.
https://github.com/jtsang4/umi-plugin-externals

Last synced: 8 days ago
JSON representation

📤 A umi plugin to help you make local built JS module as webpack external bundle.

Awesome Lists containing this project

README

        

# umi-plugin-externals

[![NPM version](https://img.shields.io/npm/v/umi-plugin-externals.svg?style=flat)](https://npmjs.org/package/umi-plugin-externals)
[![NPM downloads](http://img.shields.io/npm/dm/umi-plugin-externals.svg?style=flat)](https://npmjs.org/package/umi-plugin-externals)

A umi plugin to help you make local built **JS** module as webpack external bundle, you can pre-build some modules then use this plugin to improve the performance of building.

## Why I need this plugin?

1. You want to improve building performance of umi.
2. Maybe you don't want to upload external modules to CDN.
3. **More importantly** maybe your HTML is not generated by umi(like server side rendering by template).

## Install

```bash
npm install umi-plugin-externals --save-dev
```

or yarn

```bash
yarn add umi-plugin-externals -D
```

## Usage

Configure in `.umirc.js`,

```js
export default {
plugins: [
[
'umi-plugin-externals',
// options, given an example of 'lodash'
{
'lodash': ['_', 'local/path/to/lodash'],
},
],
],
}
```

## Options

```typescript
{
[moduleName: string]: [string | object | Function | RegExp, string];
}
```

The key of option is webpack [Externals](https://webpack.js.org/configuration/externals/)'s key, the value of option should be an array.

For the array, the first item is webpack [Externals](https://webpack.js.org/configuration/externals/)'s value(a global variable string is recommended), the second item is the local built module path in file system, you should pre-built the module and set corresponding global variable in the pre-built bundle.

## LICENSE

MIT