Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eemeli/dev-console.macro
A Babel macro that removes console prints in production
https://github.com/eemeli/dev-console.macro
Last synced: 2 months ago
JSON representation
A Babel macro that removes console prints in production
- Host: GitHub
- URL: https://github.com/eemeli/dev-console.macro
- Owner: eemeli
- License: isc
- Archived: true
- Created: 2018-05-30T15:32:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-30T15:41:51.000Z (over 6 years ago)
- Last Synced: 2024-10-02T07:58:12.555Z (4 months ago)
- Language: JavaScript
- Homepage: https://npm.im/dev-console.macro
- Size: 6.84 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - dev-console.macro
README
# dev-console.macro
This is a [Babel](https://babeljs.io/) macro to be used with [babel-plugin-macros](https://www.npmjs.com/package/babel-plugin-macros). By default, it'll remove all `console.log`, `console.warn` and `console.error` calls from `production` builds. Internally it uses [babel-plugin-transform-remove-console](https://babeljs.io/docs/plugins/transform-remove-console/).
## Installation
```
npm install --save-dev dev-console.macro babel-plugin-macros
```## Usage
```js
import console from 'dev-console.macro'console.log('This is a', 'log message')
// Removed in production & staging buildsconsole.error('Nothing to see here')
// Removed in production buildsconst w = console.warn.bind(console)
w("Being tricky won't help you")
// In production & staging, `w` will be defined as `function () {}`
```## Configuration
First of all, you'll need to have `"macros"` included as a Babel plugin. In some environments like [react-scripts 2.0](https://github.com/facebook/create-react-app/issues/3815) this will already be done for you; for more details please refer to the [babel-plugin-macros documentation](https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md).
If you'd like to customise this macro's behaviour in specific environments and/or exclude specific methods of `console` from being removed, set the value of the `remove-console` key in your [babel-plugin-macros config](https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/author.md#config-experimental). The default config corresponds to this:
```json
{
"remove-console": {
"production": true,
"staging": { "exclude": ["error"] }
}
}
```