# webpack-format-messages

> Beautiful formatting for Webpack messages; ported from Create React App!

Latest version **3.0.1** (published 2021-07-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install webpack-format-messages
pnpm add webpack-format-messages
yarn add webpack-format-messages
bun add webpack-format-messages
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2021-07-22 |
| First published | 2017-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=6 |
| Dependencies | 1 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 111 |
| Author | Luke Edwards |
| Maintainers | lukeed |
| Keywords | create-react-app, console, messages, webpack, pretty, format, stats, output |

## Links

- npm: https://www.npmjs.com/package/webpack-format-messages
- Repository: https://github.com/lukeed/webpack-format-messages
- Homepage: https://github.com/lukeed/webpack-format-messages#readme
- Issues: https://github.com/lukeed/webpack-format-messages/issues
- npm.io page: https://npm.io/package/webpack-format-messages

## Dependencies (1)

- [kleur](https://npm.io/package/kleur.md) ^4.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2021-07-22
- 3.0.0 — 2021-07-21
- 2.0.6 — 2019-11-23
- 2.0.5 — 2018-12-02
- 2.0.4 — 2018-11-22
- 2.0.3 — 2018-07-21
- 2.0.2 — 2018-07-10
- 2.0.1 — 2018-05-15
- 1.0.2 — 2018-03-10
- 1.0.1 — 2017-08-23
- 1.0.0 — 2017-07-21

## README

# webpack-format-messages

> Beautiful formatting for Webpack messages; ported from [Create React App](https://github.com/facebookincubator/create-react-app)!

The console output from CRA is very well-done! Unfortunately, the only way to use it is to install _all_ of `react-dev-utils`, which is quite a module-rich tree. While there is **nothing** wrong with this, many times I'd prefer a quick install for my custom Webpack configs (which aren't always React-related).

If you are already using `react-dev-utils`, you do not need this module and should do this instead:

```js
const formatMessages = require('react-dev-utils/formatWebpackMessages');
```

#### Differences

The source code of this module is (nearly) a direct copy-paste of the original file. Only two modifications have been made:

1. The code has been tailored to run in a Node-specific environment --- the original can also be run in the browser.
2. The module input expects a Webpack `stats` object --- the original required a `toJson()` transformation


## Install

```
$ npm install webpack-format-messages --save-dev
```


## Usage

```js
const webpack = require('webpack');
const formatMessages = require('webpack-format-messages');
// or
const { formatMessages } = require('webpack-format-messages');

const compiler = webpack(/* config */);

compiler.hooks.invalid.tap('invalid', function() {
  console.log('Compiling...');
});

compiler.hooks.done.tap('done', (stats) => {
  const messages = formatMessages(stats);

  if (!messages.errors.length && !messages.warnings.length) {
    console.log('Compiled successfully!');
  }

  if (messages.errors.length) {
    console.log('Failed to compile.');
    messages.errors.forEach(e => console.log(e));
    return;
  }

  if (messages.warnings.length) {
    console.log('Compiled with warnings.');
    messages.warnings.forEach(w => console.log(w));
  }
});
```


## API

### formatMessages(stats)
Returns: `{ errors: string[], warnings: string[] }`

Extracts & prettifies warning and error messages from Webpack.

> **Note:** This is also the `default` export.

#### stats

Type: `Object`

A Webpack [`stats`](https://github.com/webpack/docs/wiki/node.js-api#stats) object.


### formatMessage(message)
Returns: `string`

Transforms an individual webpack `stats` message object into a string.

> **Note:** You probably don't want to use this directly! It's used by `formatMessages` for you.

## Related

* [`webpack-messages`](https://github.com/lukeed/webpack-messages) -- Wraps this module as a Webpack plugin, with lifecycle hooks


## Credits

This module is pulled directly from [`react-dev-utils`](https://github.com/facebookincubator/create-react-app/tree/master/packages/react-dev-utils), provided by Facebook Incubator.

This package exists solely as a standalone install~!

---
_Source: https://npm.io/package/webpack-format-messages · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
