Eli Perelman
8 years ago
committed by
GitHub
41 changed files with 2787 additions and 511 deletions
@ -1,27 +1,30 @@ |
|||||
# Summary |
# Summary |
||||
|
|
||||
* [Introduction](/README.md) |
* [Introduction](./README.md) |
||||
* [Installation](/installation.md) |
* [Installation](./installation.md) |
||||
* [Usage](/usage.md) |
* [Usage](./usage.md) |
||||
* [Project Layout](/project-layout.md) |
* [Project Layout](./project-layout.md) |
||||
* [FAQ](/FAQ.md) |
* [FAQ](./FAQ.md) |
||||
* [Presets](/presets/README.md) |
* [Middleware](./middleware/README.md) |
||||
* [Web](/presets/neutrino-preset-web/README.md) |
* [Presets](./presets/README.md) |
||||
* [React](/presets/neutrino-preset-react/README.md) |
* [Web](./presets/neutrino-preset-web/README.md) |
||||
* [Node.js](/presets/neutrino-preset-node/README.md) |
* [React](./presets/neutrino-preset-react/README.md) |
||||
* [Airbnb](/presets/neutrino-preset-airbnb-base/README.md) |
* [Node.js](./presets/neutrino-preset-node/README.md) |
||||
* [Karma](/presets/neutrino-preset-karma/README.md) |
* [Airbnb](./presets/neutrino-preset-airbnb-base/README.md) |
||||
* [Mocha](/presets/neutrino-preset-mocha/README.md) |
* [Karma](./presets/neutrino-preset-karma/README.md) |
||||
* [Jest](/presets/neutrino-preset-jest/README.md) |
* [Mocha](./presets/neutrino-preset-mocha/README.md) |
||||
* [Community presets](/presets/community-presets.md) |
* [Jest](./presets/neutrino-preset-jest/README.md) |
||||
* [Customization](/customization/README.md) |
* [Community presets](./presets/community-presets.md) |
||||
* [Simple](/customization/simple.md) |
* [Customization](./customization/README.md) |
||||
* [Advanced](/customization/advanced.md) |
* [Simple](./customization/simple.md) |
||||
* [Creating presets](/creating-presets.md) |
* [Advanced](./customization/advanced.md) |
||||
* [Creating linting presets](/presets/neutrino-lint-base/README.md) |
* [Creating presets](./creating-presets.md) |
||||
* [Learning Resources](/learning-resources.md) |
* [Creating linting presets](./presets/neutrino-lint-base/README.md) |
||||
* [API](/api/README.md) |
* [Learning Resources](./learning-resources.md) |
||||
* [CLI](/cli/README.md) |
* [API](./api/README.md) |
||||
* [Contributing](/contributing/README.md) |
* [CLI](./cli/README.md) |
||||
* [Development Process](/contributing/development.md) |
* [Upgrading from v4 to v5](./upgrading-neutrino.md) |
||||
* [Code of Conduct](/contributing/code-of-conduct.md) |
* [v4 Documentation](https://github.com/mozilla-neutrino/neutrino-dev/tree/docs-v4/docs) |
||||
|
* [Contributing](./contributing/README.md) |
||||
|
* [Development Process](./contributing/development.md) |
||||
|
* [Code of Conduct](./contributing/code-of-conduct.md) |
||||
|
@ -0,0 +1,124 @@ |
|||||
|
# Middleware |
||||
|
|
||||
|
The basic unit of interacting with Neutrino is middleware. In Neutrino, middleware are functions |
||||
|
that are provided a Neutrino instance for the intent of modifying configuration, listening for |
||||
|
events, getting build metadata, or augmenting with custom functionality. At its simplest, a middleware |
||||
|
function accepts a Neutrino instance argument and does nothing: |
||||
|
|
||||
|
```js |
||||
|
function middleware(neutrino) {} |
||||
|
``` |
||||
|
|
||||
|
A middleware function can also optionally accept an `options` argument which will be fed back into |
||||
|
the middleware function when used. |
||||
|
|
||||
|
```js |
||||
|
function middleware(neutrino, options) {} |
||||
|
``` |
||||
|
|
||||
|
The signature of this function is what we call "Neutrino middleware". If you're familiar with middleware from the |
||||
|
Express/connect world, this works similarly. When using Express middleware, you provide a function to Express which |
||||
|
receives arguments to modify a request or response along its lifecycle. There can be a number of middleware functions |
||||
|
that Express can load, each one potentially modifying a request or response in succession. |
||||
|
|
||||
|
Neutrino will execute middleware similarly, where each middleware function successively interacts with Neutrino along |
||||
|
the lifecycle. This is done by plugging in the middleware to Neutrino via the `use()` method. |
||||
|
|
||||
|
```js |
||||
|
const api = new Neutrino(); |
||||
|
|
||||
|
api.use(middleware); |
||||
|
api.use(middleware, options); |
||||
|
``` |
||||
|
|
||||
|
To use a concrete example, let's create middleware that adds an environment plugin: |
||||
|
|
||||
|
```js |
||||
|
const Neutrino = require('neutrino'); |
||||
|
const { EnvironmentPlugin } = require('webpack'); |
||||
|
|
||||
|
const api = new Neutrino(); |
||||
|
|
||||
|
function env(neutrino, additionalVars = []) { |
||||
|
neutrino.config |
||||
|
.plugin('env') |
||||
|
.use(EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); |
||||
|
} |
||||
|
|
||||
|
api.use(env); // or: |
||||
|
api.use(env, ['SECRET_KEY']); |
||||
|
``` |
||||
|
|
||||
|
## Loading middleware |
||||
|
|
||||
|
Additional middleware can also be loaded from a middleware function. This makes their composition simpler for |
||||
|
consumers. |
||||
|
|
||||
|
```js |
||||
|
// neutrino-middleware-env |
||||
|
const { EnvironmentPlugin } = require('webpack'); |
||||
|
|
||||
|
module.exports = (neutrino, additionalVars = []) => neutrino.config |
||||
|
.plugin('env') |
||||
|
.use(EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); |
||||
|
``` |
||||
|
|
||||
|
```js |
||||
|
// react preset (which is also middleware) |
||||
|
const env = require('./neutrino-middleware-env'); |
||||
|
|
||||
|
module.exports = neutrino => { |
||||
|
neutrino.use(env, ['SECRET_KEY']); |
||||
|
neutrino.use(/* next middleware */); |
||||
|
neutrino.use(/* next middleware */) |
||||
|
}; |
||||
|
``` |
||||
|
|
||||
|
## Configuring |
||||
|
|
||||
|
If your middleware requires configuration _outside_ of the options necessary for _running_ the middleware, |
||||
|
use a closure technique for simplifying this for your middleware consumers. In short, your module will provide a |
||||
|
function to consumers which, when executed, will return a Neutrino middleware function. Describing this in code: |
||||
|
|
||||
|
```js |
||||
|
module.exports = function wrapper(...args) { |
||||
|
return function middleware(neutrino, options) { |
||||
|
// do something with neutrino, options, and args |
||||
|
}; |
||||
|
}; |
||||
|
``` |
||||
|
|
||||
|
Let's create a contrived example using our `env` middleware. Let's use a closure to let the consumer provide an |
||||
|
alternate plugin name when creating the middleware: |
||||
|
|
||||
|
```js |
||||
|
// neutrino-middleware-env |
||||
|
const { EnvironmentPlugin } = require('webpack'); |
||||
|
|
||||
|
module.exports = (pluginName = 'env') => (neutrino, additionalVars = []) => { |
||||
|
neutrino.config |
||||
|
.plugin(pluginName) |
||||
|
.use(EnvironmentPlugin, ['NODE_ENV', ...additionalVars]); |
||||
|
}; |
||||
|
``` |
||||
|
|
||||
|
```js |
||||
|
// react preset (which is also middleware) |
||||
|
const env = require('./neutrino-middleware-env'); |
||||
|
|
||||
|
module.exports = neutrino => { |
||||
|
neutrino.use(env('ENV-PLUGIN'), ['SECRET_KEY']); |
||||
|
}; |
||||
|
``` |
||||
|
|
||||
|
## Distributing |
||||
|
|
||||
|
If you would like your middleware to be used by others, feel free to publish and distribute! By putting your middleware |
||||
|
on npm, GitHub, or another location, you can share the hard work put into abstracting away Neutrino and Webpack |
||||
|
interactions and save everyone in the community time and effort. As long as the Neutrino CLI, other middleware, or |
||||
|
presets can require your middleware, it puts no restrictions on where you want to host it. |
||||
|
|
||||
|
## Core middleware |
||||
|
|
||||
|
Neutrino maintains a number of core middleware packages which aid in creating the various preset packages we also |
||||
|
distribute. Continue onward for documentation on these various middleware packages. |
@ -0,0 +1,71 @@ |
|||||
|
# Neutrino Banner Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-banner` is Neutrino middleware for injecting string content into source code files. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-banner` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-banner |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-banner |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-banner` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const banner = require('neutrino-middleware-banner'); |
||||
|
|
||||
|
// Use with default options |
||||
|
neutrino.use(banner); |
||||
|
|
||||
|
// Also accepts options for Webpack's BannerPlugin |
||||
|
// https://webpack.js.org/plugins/banner-plugin/ |
||||
|
|
||||
|
// Usage shows the default values of this middleware: |
||||
|
neutrino.use(banner, { |
||||
|
banner: `require('source-map-support').install();`, |
||||
|
raw: true, |
||||
|
entryOnly: true |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-banner` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `banner`: Injects string content into application source code. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-banner.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-banner.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-banner |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,71 @@ |
|||||
|
# Neutrino Chunk Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-chunk` is Neutrino middleware for optimizing Webpack bundles via `CommonsChunkPlugin`. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-chunk` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-chunk |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-chunk |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-chunk` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const chunk = require('neutrino-middleware-chunk'); |
||||
|
|
||||
|
// Use with default options |
||||
|
neutrino.use(chunk); |
||||
|
|
||||
|
// Also accepts options for Webpack's CommonsChunkPlugin |
||||
|
// https://webpack.js.org/plugins/commons-chunk-plugin/ |
||||
|
|
||||
|
// Usage shows the default values of this middleware: |
||||
|
neutrino.use(chunk, { |
||||
|
minChunks: Infinity, |
||||
|
names: ['vendor', 'manifest'] |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-chunk` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `chunk`: Creates a separate file (known as a chunk), consisting of common modules shared between multiple entry |
||||
|
points. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-chunk.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-chunk.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-chunk |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,67 @@ |
|||||
|
# Neutrino Clean Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-clean` is Neutrino middleware for removing directories before building. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-clean` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-clean |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-clean |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-clean` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const clean = require('neutrino-middleware-clean'); |
||||
|
|
||||
|
// Use with default options |
||||
|
neutrino.use(clean); |
||||
|
|
||||
|
// Usage shows the default values of this middleware: |
||||
|
neutrino.use(clean, { |
||||
|
paths: [], |
||||
|
root: neutrino.options.root |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-clean` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `clean`: Removes directories before building. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-clean.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-clean.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-clean |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,69 @@ |
|||||
|
# Neutrino Compile Loader Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-compile-loader` is Neutrino middleware for compiling source code with Babel. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-compile-loader` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-compile-loader |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-compile-loader |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-compile-loader` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const compile = require('neutrino-middleware-compile-loader'); |
||||
|
|
||||
|
neutrino.use(compile, { |
||||
|
include: [], |
||||
|
exclude: [], |
||||
|
babel: {} |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
- `include` should be an array of paths to include in the compilation. Maps to Webpack's |
||||
|
[`Rule.include`](https://webpack.js.org/configuration/module/#rule-include) |
||||
|
- `babel` is a [Babel configuration object](https://babeljs.io/docs/usage/api/#options), consumed by babel-loader. Use |
||||
|
this to set properties such as `presets`, `plugins`, and `env`. |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-compile-loader` creates some conventions to make overriding the configuration easier once you are |
||||
|
ready to make changes. |
||||
|
|
||||
|
### Rules |
||||
|
|
||||
|
The following is a list of rules and their identifiers which can be overridden: |
||||
|
|
||||
|
- `compile`: Compiles JS and JSX files from the `src` directory using Babel. Contains a single loader named `babel`. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-compile-loader.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-compile-loader.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-compile-loader |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,73 @@ |
|||||
|
# Neutrino Copy Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-copy` is Neutrino middleware for copying files during building. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-copy` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-copy |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-copy |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-copy` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const copy = require('neutrino-middleware-copy'); |
||||
|
|
||||
|
// Use with default options |
||||
|
neutrino.use(copy); |
||||
|
|
||||
|
// Usage shows the default values of this middleware: |
||||
|
neutrino.use(copy, { |
||||
|
patterns: [], |
||||
|
options: {} |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
The `patterns` and `options` are defined from the [CopyWebpackPlugin](https://github.com/kevlened/copy-webpack-plugin). |
||||
|
See their docs for details on valid values to specify. |
||||
|
|
||||
|
- `patterns`: An array of patterns specifying copy operations. |
||||
|
- `options`: An object specifying copy options. |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-copy` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `copy`: Copy files during building. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-copy.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-copy.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-copy |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,67 @@ |
|||||
|
# Neutrino Environment Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-copy` is Neutrino middleware for injecting environment variable definitions into |
||||
|
source code at `process.env`. Always injects `process.env.NODE_ENV`, unless overridden. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-env` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-env |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-env |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-env` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const env = require('neutrino-middleware-env'); |
||||
|
|
||||
|
// Use with default options |
||||
|
neutrino.use(env); |
||||
|
|
||||
|
// Usage with additional environment variables |
||||
|
neutrino.use(env, ['SECRET_KEY']); |
||||
|
``` |
||||
|
|
||||
|
This middleware optionally accepts an array of environment variables to additionally inject into source code. |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-env` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `env`: Inject environment variables into source code at `process.env`. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-env.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-env.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-env |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,138 @@ |
|||||
|
# Neutrino ESLint Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-eslint` is Neutrino middleware for linting source code using ESLint and eslint-loader. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-eslint` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-eslint |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-eslint |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-eslint` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const eslint = require('neutrino-middleware-eslint'); |
||||
|
|
||||
|
// Usage shows default values |
||||
|
neutrino.use(eslint, { |
||||
|
test: /\.(js|jsx)$/, |
||||
|
include: [], /* Should specify either include or exclude */ |
||||
|
exclude: [], /* Should specify either include or exclude */ |
||||
|
eslint: { |
||||
|
failOnError: process.env.NODE_ENV !== 'development', |
||||
|
emitWarning: process.env.NODE_ENV !== 'development', |
||||
|
emitError: process.env.NODE_ENV !== 'development', |
||||
|
cwd: neutrino.options.root, |
||||
|
useEslintrc: false, |
||||
|
root: true, |
||||
|
plugins: ['babel'], |
||||
|
baseConfig: {}, |
||||
|
envs: ['es6'], |
||||
|
parser: 'babel-eslint', |
||||
|
parserOptions: { |
||||
|
ecmaVersion: 2017, |
||||
|
sourceType: 'module', |
||||
|
ecmaFeatures: { |
||||
|
objectLiteralDuplicateProperties: false, |
||||
|
generators: true, |
||||
|
impliedStrict: true |
||||
|
} |
||||
|
}, |
||||
|
settings: {}, |
||||
|
globals: ['process'], |
||||
|
rules: {} |
||||
|
} |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
- `test`: Test which files should be linted. |
||||
|
- `include`: An array of paths to include in linting. Maps to Webpack's |
||||
|
[`Rule.include`](https://webpack.js.org/configuration/module/#rule-include) |
||||
|
- `exclude`: An array of paths to exclude from linting. Maps to Webpack's |
||||
|
[`Rule.exclude`](https://webpack.js.org/configuration/module/#rule-exclude) |
||||
|
- `eslint`: An ESLint CLIEngine configuration object for configuring ESLint. Use this to configure rules, |
||||
|
plugins, and other [ESLint options](http://eslint.org/docs/user-guide/configuring). |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-eslint` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Rules |
||||
|
|
||||
|
The following is a list of rules and their identifiers which can be overridden: |
||||
|
|
||||
|
- `lint`: By default, lints JS and JSX files from included directories using ESLint. Contains a single loader named |
||||
|
`eslint`. |
||||
|
|
||||
|
## Information |
||||
|
|
||||
|
This middleware will show errors and warnings in the console during development, and will cause a failure when |
||||
|
creating a build bundle. |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
If you want your preset or middleware to also extend from another **ESLint configuration or preset** that you have made |
||||
|
a dependency, you must use `baseConfig.extends` rather than just `extends`. This is a limitation of ESLint, not this |
||||
|
middleware. |
||||
|
|
||||
|
--- |
||||
|
|
||||
|
This middleware only configures a target environment for `es6`, leaving other build middleware free to add their own |
||||
|
target environments. If your middleware puts restrictions on which environments it is capable of running, please |
||||
|
document that clearly in your middleware. |
||||
|
|
||||
|
## eslintrc Config |
||||
|
|
||||
|
`neutrino-middleware-eslint` also provides a method for getting the ESLint configuration suitable for use in an eslintrc |
||||
|
file. Typically this is used for providing hints or fix solutions to the development environment, e.g. IDEs and text |
||||
|
editors. Doing this requires [creating an instance of the Neutrino API](../../api/README.md) and providing the presets uses. |
||||
|
If you keep this information in `neutrino.presets` in package.json, this should be relatively straightforward. By |
||||
|
providing all the presets used to Neutrino, you can ensure all the linting options used across all presets will be |
||||
|
merged together for your development environment, without the need for copying, duplication, or loss of organization and |
||||
|
separation. |
||||
|
|
||||
|
_Example: Create a .eslintrc.js file in the root of the project._ |
||||
|
|
||||
|
```js |
||||
|
// .eslintrc.js |
||||
|
const Neutrino = require('neutrino'); |
||||
|
const pkg = require('./package.json'); |
||||
|
const api = new Neutrino(); |
||||
|
|
||||
|
pkg.neutrino.presets.map(preset => neutrino.use(preset)); |
||||
|
|
||||
|
module.exports = api.eslintrc(); |
||||
|
``` |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-eslint.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-eslint.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-eslint |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,70 @@ |
|||||
|
# Neutrino Font Loader Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-font-loader` is Neutrino middleware for loading and importing font files from modules. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-font-loader` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-font-loader |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-font-loader |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-font-loader` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const fonts = require('neutrino-middleware-font-loader'); |
||||
|
|
||||
|
// Use with default options |
||||
|
neutrino.use(fonts); |
||||
|
|
||||
|
// Usage showing default options |
||||
|
neutrino.use(fonts, { |
||||
|
limit: '10000' |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
- `limit`: Return a Data URL if the file is smaller than a byte limit. |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-font-loader` creates some conventions to make overriding the configuration easier once you are |
||||
|
ready to make changes. |
||||
|
|
||||
|
### Rules |
||||
|
|
||||
|
The following is a list of rules and their identifiers which can be overridden: |
||||
|
|
||||
|
- `woff`: Allows importing WOFF font files from modules. Contains a single loader named `url`. |
||||
|
- `ttf`: Allows importing TTF font files from modules. Contains a single loader named `url`. |
||||
|
- `eot`: Allows importing EOT font files from modules. Contains a single loader named `file`. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-font-loader.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-font-loader.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-font-loader |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,75 @@ |
|||||
|
# Neutrino HTML Template Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-html-template` is Neutrino middleware for automatically creating HTML files for configured |
||||
|
entry-points. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-html-template` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-html-template |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-html-template |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-html-template` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const template = require('neutrino-middleware-html-template'); |
||||
|
|
||||
|
// Usage shows default values |
||||
|
// Accepts options specified by HtmlWebpackTemplate |
||||
|
// https://github.com/jaketrent/html-webpack-template |
||||
|
neutrino.use(template, { |
||||
|
inject: false, |
||||
|
appMountId: 'root', |
||||
|
xhtml: true, |
||||
|
mobile: true, |
||||
|
minify: { |
||||
|
useShortDoctype: true, |
||||
|
keepClosingSlash: true, |
||||
|
collapseWhitespace: true, |
||||
|
preserveLineBreaks: true |
||||
|
} |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-html-template` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `html`: Automatically generates HTML files for configured entry-points. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-html-template.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-html-template.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-html-template |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,61 @@ |
|||||
|
# Neutrino Hot Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-hot` is Neutrino middleware for enabled Hot Module Replacement with Webpack's |
||||
|
`HotModuleReplacementPlugin`. This middleware is usually only added during development. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-hot` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-hot |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-hot |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-hot` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const hot = require('neutrino-middleware-hot'); |
||||
|
|
||||
|
neutrino.use(hot); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-hot` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `hot`: Enables hot module replacement. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-hot.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-hot.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-hot |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,60 @@ |
|||||
|
# Neutrino HTML Loader Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-html-loader` is Neutrino middleware for loading and importing HTML files from modules. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-html-loader` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-html-loader |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-html-loader |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-html-loader` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const html = require('neutrino-middleware-html-loader'); |
||||
|
|
||||
|
neutrino.use(html); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-html-loader` creates some conventions to make overriding the configuration easier once you are |
||||
|
ready to make changes. |
||||
|
|
||||
|
### Rules |
||||
|
|
||||
|
The following is a list of rules and their identifiers which can be overridden: |
||||
|
|
||||
|
- `html`: Allows importing HTML files from modules. Contains a single loader named `file`. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-html-loader.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-html-loader.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-html-loader |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,70 @@ |
|||||
|
# Neutrino Image Loader Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-image-loader` is Neutrino middleware for loading and importing image files from modules. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-image-loader` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-image-loader |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-image-loader |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-image-loader` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const images = require('neutrino-middleware-image-loader'); |
||||
|
|
||||
|
// Use with default options |
||||
|
neutrino.use(images); |
||||
|
|
||||
|
// Usage showing default options |
||||
|
neutrino.use(images, { |
||||
|
limit: 8192 |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
- `limit`: Return a Data URL if the file is smaller than a byte limit. |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-image-loader` creates some conventions to make overriding the configuration easier once you are |
||||
|
ready to make changes. |
||||
|
|
||||
|
### Rules |
||||
|
|
||||
|
The following is a list of rules and their identifiers which can be overridden: |
||||
|
|
||||
|
- `img`: Allows importing JPEG, PNG, and GIF files from modules. Contains a single loader named `url`. |
||||
|
- `svg`: Allows importing SVG files from modules. Contains a single loader named `url`. |
||||
|
- `ico`: Allows importing ICO files from modules. Contains a single loader named `url`. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-image-loader.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-image-loader.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-image-loader |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,75 @@ |
|||||
|
# Neutrino Loader Merge Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-loader-merge` is Neutrino middleware for easily performing a deep merge of options into |
||||
|
a named rule and named loader in a Neutrino configuration. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-loader-merge` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-loader-merge |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-loader-merge |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-loader-merge` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const loaderMerge = require('neutrino-middleware-loader-merge'); |
||||
|
|
||||
|
neutrino.use(loaderMerge('compile', 'babel'), { |
||||
|
plugins: ['object-rest-spread'] |
||||
|
}); |
||||
|
|
||||
|
// Equivalent to: |
||||
|
neutrino.config.module |
||||
|
.rule('compile') |
||||
|
.use('babel') |
||||
|
.tap(options => require('deepmerge')(options, { |
||||
|
plugins: ['object-rest-spread'] |
||||
|
})); |
||||
|
``` |
||||
|
|
||||
|
This middleware is a factory intended to be invoked with a rule name and a loader name for which to extend the options. |
||||
|
Upon invoking, it will return a middleware function to be provided to Neutrino's `use()` method. |
||||
|
|
||||
|
```js |
||||
|
const middleware = loaderMerge(ruleName, loaderName); |
||||
|
|
||||
|
neutrino.use(middleware, options); |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-loader-merge` does not create any of its own conventions; it is only middleware |
||||
|
for extending the options for a rule loader which has create its own conventions. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-loader-merge.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-loader-merge.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-loader-merge |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,62 @@ |
|||||
|
# Neutrino Minify Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-hot` is Neutrino middleware for minifying source code using |
||||
|
[`BabiliWebpackPlugin`](https://www.npmjs.com/package/babili-webpack-plugin). This middleware is usually only |
||||
|
added during production builds. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-minify` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-minify |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-minify |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-minify` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const minify = require('neutrino-middleware-minify'); |
||||
|
|
||||
|
neutrino.use(minify); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-minify` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `minify`: Minifies source code using `BabiliWebpackPlugin`. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-minify.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-minify.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-minify |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,60 @@ |
|||||
|
# Neutrino Named Modules Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-named-modules` is Neutrino middleware for enabling named modules output via `NamedModulesPlugin`. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-named-modules` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-named-modules |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-named-modules |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-named-modules` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const namedModules = require('neutrino-middleware-named-modules'); |
||||
|
|
||||
|
neutrino.use(namedModules); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-named-modules` creates some conventions to make overriding the configuration easier once you are |
||||
|
ready to make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `named-modules`: Enables named modules for improved debugging and console output. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-named-modules.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-named-modules.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-named-modules |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,60 @@ |
|||||
|
# Neutrino Progress Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-progress` is Neutrino middleware for displaying a progress bar showing the progress of a build. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-progress` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-progress |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-progress |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-progress` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const progress = require('neutrino-middleware-progress'); |
||||
|
|
||||
|
neutrino.use(progress); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-progress` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `progress`: Displays a bar showing progression of build. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-progress.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-progress.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-progress |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,69 @@ |
|||||
|
# Neutrino Start Server Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-start-server` is Neutrino middleware for starting a Node.js server for a file upon |
||||
|
completion of a build. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-start-server` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-start-server |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-start-server |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-start-server` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const server = require('neutrino-middleware-start-server'); |
||||
|
|
||||
|
// Use with default options, starting the server |
||||
|
// for the main entry point, neutrino.options.entry |
||||
|
neutrino.use(server); |
||||
|
|
||||
|
// Usage with custom server file to start |
||||
|
neutrino.use(server, { name: 'custom.js' }); |
||||
|
``` |
||||
|
|
||||
|
By default this middleware will start a server with the single entry point configured in Neutrino. |
||||
|
This middleware optionally accepts an object with a `name` property for a path to a module which to start the server. |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-start-server` creates some conventions to make overriding the configuration easier once you are ready to |
||||
|
make changes. |
||||
|
|
||||
|
### Plugins |
||||
|
|
||||
|
The following is a list of plugins and their identifiers which can be overridden: |
||||
|
|
||||
|
- `start-server`: Start a Node.js for a configured entry point or specified file. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-start-server.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-start-server.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-start-server |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,61 @@ |
|||||
|
# Neutrino Style Loader Middleware |
||||
|
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
||||
|
|
||||
|
`neutrino-middleware-style-loader` is Neutrino middleware for loading and importing stylesheets from modules. |
||||
|
|
||||
|
## Requirements |
||||
|
|
||||
|
- Node.js v6.9+ |
||||
|
- Yarn or npm client |
||||
|
- Neutrino v5 |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
`neutrino-middleware-style-loader` can be installed via the Yarn or npm clients. |
||||
|
|
||||
|
#### Yarn |
||||
|
|
||||
|
```bash |
||||
|
❯ yarn add neutrino-middleware-style-loader |
||||
|
``` |
||||
|
|
||||
|
#### npm |
||||
|
|
||||
|
```bash |
||||
|
❯ npm install --save neutrino-middleware-style-loader |
||||
|
``` |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
`neutrino-middleware-style-loader` can be consumed from the Neutrino API, middleware, or presets. Require this package |
||||
|
and plug it into Neutrino: |
||||
|
|
||||
|
```js |
||||
|
const styles = require('neutrino-middleware-style-loader'); |
||||
|
|
||||
|
neutrino.use(styles); |
||||
|
``` |
||||
|
|
||||
|
## Customization |
||||
|
|
||||
|
`neutrino-middleware-style-loader` creates some conventions to make overriding the configuration easier once you are |
||||
|
ready to make changes. |
||||
|
|
||||
|
### Rules |
||||
|
|
||||
|
The following is a list of rules and their identifiers which can be overridden: |
||||
|
|
||||
|
- `css`: Allows importing CSS stylesheets from modules. Contains two loaders named `style` and `css` which use |
||||
|
`style-loader` and `css-loader`, respectively. |
||||
|
|
||||
|
## Contributing |
||||
|
|
||||
|
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
||||
|
containing all resources for developing Neutrino and its core presets. Follow the |
||||
|
[contributing guide](../../contributing/README.md) for details. |
||||
|
|
||||
|
[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-style-loader.svg |
||||
|
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-style-loader.svg |
||||
|
[npm-url]: https://npmjs.org/package/neutrino-middleware-style-loader |
||||
|
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
||||
|
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -1,200 +0,0 @@ |
|||||
# Neutrino Lint Base |
|
||||
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
|
||||
|
|
||||
`neutrino-lint-base` is an abstract Neutrino preset base that makes creating ESLint-based presets simpler. By creating |
|
||||
a linting preset that extends from `neutrino-lint-base`, the development overhead and dependencies needed can be |
|
||||
significantly reduced. Use it as a baseline to create your own linting presets easier and more quickly. |
|
||||
|
|
||||
## Features |
|
||||
|
|
||||
- Quickly and easily create your own Neutrino linting presets |
|
||||
- Modern Babel knowledge supporting ES modules, JSX (when used with React preset), Web and Node.js apps |
|
||||
- Highly visible during development, fails compilation when building for production |
|
||||
- Easily extensible to customize your project as needed |
|
||||
|
|
||||
## Development Requirements |
|
||||
|
|
||||
- Node.js v6.9+ |
|
||||
- Yarn or npm client |
|
||||
- Neutrino v4 |
|
||||
|
|
||||
## Installation |
|
||||
|
|
||||
`neutrino-lint-base` can be installed via the Yarn or npm clients. |
|
||||
|
|
||||
#### Yarn |
|
||||
|
|
||||
```bash |
|
||||
❯ yarn add neutrino-lint-base |
|
||||
``` |
|
||||
|
|
||||
#### npm |
|
||||
|
|
||||
```bash |
|
||||
❯ npm install --save neutrino-lint-base |
|
||||
``` |
|
||||
|
|
||||
Your project should also install any dependencies needed to operate based on options passed to `eslint-loader` or |
|
||||
ESLint's CLIEngine. |
|
||||
|
|
||||
## Project Layout |
|
||||
|
|
||||
`neutrino-lint-base` follows the standard [project layout](/project-layout.md) specified by Neutrino. This |
|
||||
means that by default all project source code should live in a directory named `src` in the root of the |
|
||||
project. The `.js` or `.jsx` files in this directory are the ones that will be linted by your preset. |
|
||||
|
|
||||
## Creating the preset |
|
||||
|
|
||||
Your preset will follow the same guidelines for normally creating Neutrino presets, with your preset extending |
|
||||
`neutrino-lint-base`. This starts out by having your package module export a function which accepts a Neutrino instance: |
|
||||
|
|
||||
```js |
|
||||
module.exports = neutrino => { |
|
||||
// ... |
|
||||
}; |
|
||||
``` |
|
||||
|
|
||||
The next step is to `require`, or `import` if your package supports it, `neutrino-lint-base` and execute it with |
|
||||
Neutrino. This will add the lint base's configuration to Neutrino for your preset to extend further: |
|
||||
|
|
||||
```js |
|
||||
const lint = require('neutrino-lint-base'); |
|
||||
|
|
||||
module.exports = neutrino => { |
|
||||
lint(neutrino); |
|
||||
// ... |
|
||||
}; |
|
||||
``` |
|
||||
|
|
||||
Now comes the core of your own preset. By extending from `neutrino-lint-base`'s "lint" rule and "eslint" loader, you |
|
||||
can manipulate the options as you desire. Consider using a package such as |
|
||||
[`deepmerge`](https://www.npmjs.com/package/deepmerge) to make extending these options easier: |
|
||||
|
|
||||
_Example: Create a preset that shuts off semicolons from being required by ESLint._ |
|
||||
|
|
||||
```js |
|
||||
const lint = require('neutrino-lint-base'); |
|
||||
const merge = require('deepmerge'); |
|
||||
|
|
||||
module.exports = neutrino => { |
|
||||
lint(neutrino); |
|
||||
neutrino.config.module |
|
||||
.rule('lint') |
|
||||
.loader('eslint', props => merge(props, { |
|
||||
options: { |
|
||||
rules: { |
|
||||
semi: 'off' |
|
||||
} |
|
||||
} |
|
||||
})); |
|
||||
}; |
|
||||
``` |
|
||||
|
|
||||
_Example: Create a preset that lints a project using the Airbnb base ESLint rules._ |
|
||||
|
|
||||
```js |
|
||||
const lint = require('neutrino-lint-base'); |
|
||||
const merge = require('deepmerge'); |
|
||||
|
|
||||
module.exports = neutrino => { |
|
||||
lint(neutrino); |
|
||||
neutrino.config.module |
|
||||
.rule('lint') |
|
||||
.loader('eslint', props => merge(props, { |
|
||||
options: { |
|
||||
baseConfig: { |
|
||||
extends: ['airbnb-base'] |
|
||||
} |
|
||||
} |
|
||||
})); |
|
||||
}; |
|
||||
``` |
|
||||
|
|
||||
Visit the [creating presets](/creating-presets.md) documentation for more detailed information on creating your own |
|
||||
custom preset. |
|
||||
|
|
||||
## Customization |
|
||||
|
|
||||
`neutrino-lint-base` creates some conventions to make overriding the configuration easier once you are ready to |
|
||||
make changes. |
|
||||
|
|
||||
### Rules |
|
||||
|
|
||||
The following is a list of rules and their identifiers which can be overridden: |
|
||||
|
|
||||
- `lint`: Lints JS and JSX files from the `src` directory using ESLint. Contains a single loader named `eslint`. |
|
||||
|
|
||||
## Information |
|
||||
|
|
||||
The lint base will show errors and warnings in the console during development, and will cause a failure when |
|
||||
creating a build bundle. |
|
||||
|
|
||||
--- |
|
||||
|
|
||||
If you want your preset to also extend from another ESLint configuration that you have made a dependency, you must use |
|
||||
`baseConfig.extends` rather than just `extends`. This is a limitation of ESLint, not this lint base. |
|
||||
|
|
||||
```js |
|
||||
const lint = require('neutrino-lint-base'); |
|
||||
const merge = require('deepmerge'); |
|
||||
|
|
||||
module.exports = neutrino => { |
|
||||
lint(neutrino); |
|
||||
neutrino.config.module |
|
||||
.rule('lint') |
|
||||
.loader('eslint', props => merge(props, { |
|
||||
options: { |
|
||||
baseConfig: { |
|
||||
extends: [ |
|
||||
'YOUR_ESLINT_CONFIGURATION_BASE_A', |
|
||||
'YOUR_ESLINT_CONFIGURATION_BASE_B' |
|
||||
] |
|
||||
} |
|
||||
} |
|
||||
})); |
|
||||
}; |
|
||||
``` |
|
||||
|
|
||||
--- |
|
||||
|
|
||||
The linting base only configures a target environment for `es6`, leaving other build presets free to add their own |
|
||||
target environments. If your preset puts restrictions on which environments it is capable of running, please document |
|
||||
that clearly in your preset. |
|
||||
|
|
||||
For specifics on what options are configured when using this linting base, please |
|
||||
[view the source](https://github.com/mozilla-neutrino/neutrino-dev/blob/master/packages/neutrino-lint-base/src/index.js). |
|
||||
|
|
||||
## eslintrc Config |
|
||||
|
|
||||
`neutrino-lint-base` also provides a method for getting the ESLint configuration suitable for use in an eslintrc file. |
|
||||
Typically this is used for providing hints or fix solutions to the development environment, e.g. IDEs and text editors. |
|
||||
Doing this requires [creating an instance of the Neutrino API](/api/README.md) and providing the presets uses. If you |
|
||||
keep this information in `config.presets` in package.json, this should be relatively straightforward. By providing |
|
||||
all the presets used to Neutrino, you can ensure all the linting options used across all those preset will be merged |
|
||||
together for your development environment, without the need for copying, duplication, or loss of organization and |
|
||||
separation. |
|
||||
|
|
||||
_Example: Create a .eslintrc.js file in the root of the project._ |
|
||||
|
|
||||
```js |
|
||||
// .eslintrc.js |
|
||||
const Neutrino = require('neutrino'); |
|
||||
const pkg = require('./package.json'); |
|
||||
const api = new Neutrino(pkg.config.presets); |
|
||||
|
|
||||
module.exports = api.custom.eslintrc(); |
|
||||
``` |
|
||||
|
|
||||
--- |
|
||||
|
|
||||
## Contributing |
|
||||
|
|
||||
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
|
||||
containing all resources for developing Neutrino and its core presets. Follow the |
|
||||
[contributing guide](/contributing/README.md) for details. |
|
||||
|
|
||||
[npm-image]: https://img.shields.io/npm/v/neutrino-lint-base.svg |
|
||||
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-lint-base.svg |
|
||||
[npm-url]: https://npmjs.org/package/neutrino-lint-base |
|
||||
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
|
||||
[slack-url]: https://neutrino-slack.herokuapp.com/ |
|
@ -0,0 +1,213 @@ |
|||||
|
# Upgrading from Neutrino v4 to v5 |
||||
|
|
||||
|
Neutrino v5 introduces a number of changes, with some of them being breaking changes. To upgrade from Neutrino v4 |
||||
|
to v5, be sure to check this list for tasks you may need to perform to use this latest version: |
||||
|
|
||||
|
- Updates to config for creating plugins (from webpack-chain v3 upgrade): |
||||
|
|
||||
|
```js |
||||
|
// Creating plugins in v4 |
||||
|
neutrino.config |
||||
|
.plugin(name) |
||||
|
.use(WebpackPlugin, ...args) |
||||
|
|
||||
|
// Creating plugins in v5 |
||||
|
neutrino.config |
||||
|
.plugin(name) |
||||
|
.use(WebpackPlugin, args) |
||||
|
``` |
||||
|
|
||||
|
- Updates to config for modifying plugins (from webpack-chain v3 upgrade): |
||||
|
|
||||
|
```js |
||||
|
// Modifying plugins in v4 |
||||
|
neutrino.config |
||||
|
.plugin(name) |
||||
|
.inject((Plugin, args) => new Plugin(...newArgs)) |
||||
|
|
||||
|
// Modifying plugins in v5 |
||||
|
neutrino.config |
||||
|
.plugin(name) |
||||
|
.tap(args => newArgs); |
||||
|
``` |
||||
|
|
||||
|
- Updates to config for creating loaders (from webpack-chain v3 upgrade): |
||||
|
|
||||
|
```js |
||||
|
// Creating loaders in v4 |
||||
|
neutrino.config.module |
||||
|
.rule('compile') |
||||
|
.loader('babel', 'babel-loader', { |
||||
|
options: { |
||||
|
plugins: ['object-rest-spread'] |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
// Creating loaders in v5 |
||||
|
neutrino.config |
||||
|
.rule('compile') |
||||
|
.use('babel') |
||||
|
.loader('babel-loader') |
||||
|
.options({ plugins: ['object-rest-spread'] }); |
||||
|
``` |
||||
|
|
||||
|
- Updates to config for modifying loaders (from webpack-chain v3 upgrade). The function now gets its options directly |
||||
|
instead of being nested in an object: |
||||
|
|
||||
|
```js |
||||
|
// Modifying loaders in v4 |
||||
|
neutrino.config.module |
||||
|
.rule('compile') |
||||
|
.loader('babel', props => merge(props, { |
||||
|
options: { |
||||
|
plugins: ['object-rest-spread'] |
||||
|
} |
||||
|
})); |
||||
|
|
||||
|
// Modifying loaders in v5 |
||||
|
neutrino.config.module |
||||
|
.rule('compile') |
||||
|
.use('babel') |
||||
|
.tap(options => merge(options, { plugins: ['object-rest-spread'] })); |
||||
|
``` |
||||
|
|
||||
|
- Updates to `include` and `exclude` for rules (from webpack-chain v3). In the previous webpack-chain |
||||
|
package, `include` and `exclude` were functions where you provided paths as arguments. These are now |
||||
|
`ChainedMap`s, making them much more extensible should you need to manipulate these values: |
||||
|
|
||||
|
```js |
||||
|
// Adding rule includes and excludes in v4 |
||||
|
neutrino.config.module |
||||
|
.rule('compile') |
||||
|
.include(x, y) |
||||
|
.exclude(x, y); |
||||
|
|
||||
|
// Adding rule includes and excludes in v5 |
||||
|
neutrino.config.module |
||||
|
.rule('compile') |
||||
|
.include |
||||
|
.add(x) |
||||
|
.add(y) |
||||
|
.end() |
||||
|
.exclude |
||||
|
.add(x) |
||||
|
.add(y); |
||||
|
|
||||
|
// You can also use .merge() to add multiple paths at once: |
||||
|
neutrino.config.module |
||||
|
.rule('compile') |
||||
|
.include.merge([x, y]).end() |
||||
|
.exclude.merge([x, y]); |
||||
|
``` |
||||
|
|
||||
|
- Simple configuration via package.json now done from top-level `neutrino` object. Rename `config` to `neutrino`, and |
||||
|
rename `config.neutrino` to `neutrino.config`. Presets also fall under this `neutrino` object. The `custom` object has |
||||
|
been renamed to `options`. |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
"neutrino": { |
||||
|
"config": { |
||||
|
"entry": { |
||||
|
"vendor": ["react"] |
||||
|
} |
||||
|
}, |
||||
|
"presets": [ |
||||
|
"neutrino-preset-react" |
||||
|
], |
||||
|
"options": { |
||||
|
"mocha": { |
||||
|
"reporter": "nyan" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
- The Web preset has renamed its styling rule from `css` to `style`: |
||||
|
|
||||
|
```js |
||||
|
// v4 API for Web preset |
||||
|
neutrino.config.module.rule('css') |
||||
|
|
||||
|
// v5 API for Web preset |
||||
|
neutrino.config.module.rule('style') |
||||
|
``` |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
"neutrino": { |
||||
|
"config": { |
||||
|
"module": { |
||||
|
"rule": { |
||||
|
"style": {} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
- Jest upgraded to v19, which changes the option `testPathDirs` to `roots`. Jest options set using |
||||
|
package.json can now only be done at `neutrino.options.jest` (no more package.json `jest`); |
||||
|
- Linting base is deprecated in favor of `neutrino-middleware-eslint`: |
||||
|
|
||||
|
```js |
||||
|
// v4 API |
||||
|
const lint = require('neutrino-lint-base'); |
||||
|
|
||||
|
lint(neutrino); |
||||
|
neutrino.config.module |
||||
|
.rule('lint') |
||||
|
.loader('eslint', props => merge(props, { rules: { /* */ } })); |
||||
|
|
||||
|
// v5 API |
||||
|
const eslint = require('neutrino-middleware-eslint'); |
||||
|
|
||||
|
neutrino.use(eslint, { |
||||
|
rules: { /* */ } |
||||
|
}) |
||||
|
``` |
||||
|
|
||||
|
- When using a linting preset or consuming anything with `neutrino-middleware-eslint`, the `eslintrc()` method has been |
||||
|
moved from `neutrino.custom.eslintrc` to `neutrino.eslintrc`: |
||||
|
|
||||
|
```js |
||||
|
// v4 API |
||||
|
neutrino.custom.eslintrc(); |
||||
|
|
||||
|
// v5 API |
||||
|
neutrino.eslintrc(); |
||||
|
``` |
||||
|
|
||||
|
- The Neutrino API no longer accepts preset strings in its constructor. The constructor now accepts an options object to |
||||
|
be set at `neutrino.options`: |
||||
|
|
||||
|
```js |
||||
|
const Neutrino = require('neutrino'); |
||||
|
const api = new Neutrino({ mocha: { reporter: 'nyan' } }); |
||||
|
|
||||
|
api.options.mocha.reporter // "nyan" |
||||
|
``` |
||||
|
|
||||
|
- Since the Neutrino API no longer accepts preset strings in its constructor, you must now pass presets and middleware |
||||
|
as code/functions to the `.use()` method. This means the API no longer does preset module resolution. This has been |
||||
|
moved to the CLI. |
||||
|
|
||||
|
```js |
||||
|
// v4 API |
||||
|
const Neutrino = require('neutrino'); |
||||
|
const api = new Neutrino(['neutrino-preset-node', 'neutrino-preset-mocha']); |
||||
|
|
||||
|
// v5 API |
||||
|
const Neutrino = require('neutrino'); |
||||
|
const api = new Neutrino(); |
||||
|
|
||||
|
api.use(require('neutrino-preset-node')); |
||||
|
api.use(require('neutrino.preset-mocha')); |
||||
|
``` |
||||
|
|
||||
|
- `neutrino.getWebpackOptions()` no longer caches the configuration after being called. |
||||
|
- Using a `node` target no longer skips the watcher for a builder, it now uses the Webpack source watcher. This means |
||||
|
commands like `neutrino start && node build` is obsolete. `neutrino build && node build` would work to start a Node |
||||
|
instance for production-built bundles. |
Loading…
Reference in new issue