Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Remove reference to fork middleware in library preset by prompoting m…
Browse files Browse the repository at this point in the history
…ultiple webpack outputs (#1127)

* Remove reference to fork middleware in library preset by prompoting multiple webpack outputs

* Document multiple builds from usage
  • Loading branch information
eliperelman committed Sep 20, 2018
1 parent 1b01fed commit d48eb35
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
22 changes: 22 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,28 @@ module.exports = {
}
```

## Generating multiple builds

Webpack supports the ability to run multiple builds by exporting an array of
configurations instead of a single configuration. You can also use Neutrino to
drive this process by exporting multiple Neutrino configuration outputs from a
`webpack.config.js` or by calling `webpack` multiple times.

```js
// webpack.config.js
const neutrino = require('neutrino');

const config = neutrino().webpack();

module.exports = [
// first build configuration
config,

// second build configuration
{ ...config, libraryTarget: 'commonjs2' },
];
```

## Inspecting the generated webpack config

The `neutrino --inspect` command can be used to write out a stringified version of the generated
Expand Down
36 changes: 19 additions & 17 deletions packages/library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,32 +393,34 @@ require(['redux', 'redux-example'], ({ createStore }, reduxExample) => {

## Generating multiple builds

The `@neutrinojs/library` middleware can be used in conjunction with the
[`@neutrinojs/fork` middleware](https://neutrinojs.org/packages/fork/) to generate multiple library outputs
when building. Follow the instructions to install the fork middleware, and change your `.neutrinorc.js`
format as follows:
A library can be built multiple times from a `webpack.config.js` file in order to
generate multiple library outputs when building. This is done by exporting
an array of Neutrino outputs rather than a single output.

```js
const name = 'Logger';

// .neutrinorc.js
module.exports = {
use: [
(neutrino) => {
neutrino.on('prebuild', () => neutrino.use('@neutrinojs/clean'));
},
['@neutrinojs/fork', {
configs: {
// Create a named entry for each build type.
// You will most likely want to disable cleaning
// the output directory until prior to building
umd: ['@neutrinojs/library', { name, clean: false }],
commonjs2: ['@neutrinojs/library', { name, clean: false }]
}
['@neutrinojs/library', {
name: 'Logger',
clean: false
}]
]
};
```

```js
// webpack.config.js
const neutrino = require('neutrino');

const config = neutrino().webpack();

module.exports = [
config,
{ ...config, libraryTarget: 'commonjs2' }
];
```

### Rules

The following is a list of rules and their identifiers which can be overridden:
Expand Down

0 comments on commit d48eb35

Please sign in to comment.