UNPKG

2.45 kBMarkdownView Raw
1# Neutrino Loader Merge Middleware
2
3`neutrino-middleware-loader-merge` is Neutrino middleware for easily performing a deep merge of options into
4a named rule and named loader in a Neutrino configuration.
5
6[![NPM version][npm-image]][npm-url]
7[![NPM downloads][npm-downloads]][npm-url]
8[![Join the Neutrino community on Spectrum][spectrum-image]][spectrum-url]
9
10## Requirements
11
12- Node.js v6.10+
13- Yarn or npm client
14- Neutrino v7
15
16## Installation
17
18`neutrino-middleware-loader-merge` can be installed via the Yarn or npm clients.
19
20#### Yarn
21
22```bash
23❯ yarn add neutrino-middleware-loader-merge
24```
25
26#### npm
27
28```bash
29❯ npm install --save neutrino-middleware-loader-merge
30```
31
32## Usage
33
34`neutrino-middleware-loader-merge` can be consumed from the Neutrino API, middleware, or presets. Require this package
35and plug it into Neutrino:
36
37```js
38// Using function middleware format
39const loaderMerge = require('neutrino-middleware-loader-merge');
40
41neutrino.use(loaderMerge('compile', 'babel'), {
42 plugins: ['object-rest-spread']
43});
44
45// Equivalent to:
46neutrino.config.module
47 .rule('compile')
48 .use('babel')
49 .tap(options => require('deepmerge')(options, {
50 plugins: ['object-rest-spread']
51 }));
52```
53
54This middleware is a factory intended to be invoked with a rule name and a loader name for which to extend the options.
55Upon invoking, it will return a middleware function to be provided to Neutrino's `use()` method. This middleware is
56only useful to the function middleware format.
57
58```js
59const middleware = loaderMerge(ruleName, loaderName);
60
61neutrino.use(middleware, options);
62```
63
64
65## Customization
66
67`neutrino-middleware-loader-merge` does not create any of its own conventions; it is only middleware
68for extending the options for a rule loader which has created its own conventions.
69
70## Contributing
71
72This middleware is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo
73containing all resources for developing Neutrino and its core presets and middleware. Follow the
74[contributing guide](https://neutrino.js.org/contributing) for details.
75
76[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-loader-merge.svg
77[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-loader-merge.svg
78[npm-url]: https://npmjs.org/package/neutrino-middleware-loader-merge
79[spectrum-image]: https://withspectrum.github.io/badge/badge.svg
80[spectrum-url]: https://spectrum.chat/neutrino