https://github.com/ember-cli/babel-plugin-filter-imports
A babel transform for filtering out imports
https://github.com/ember-cli/babel-plugin-filter-imports
babel-plugin
Last synced: 7 months ago
JSON representation
A babel transform for filtering out imports
- Host: GitHub
- URL: https://github.com/ember-cli/babel-plugin-filter-imports
- Owner: ember-cli
- Created: 2015-06-06T04:46:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-01-18T03:02:22.000Z (about 3 years ago)
- Last Synced: 2025-06-05T00:20:00.940Z (8 months ago)
- Topics: babel-plugin
- Language: JavaScript
- Size: 1.62 MB
- Stars: 18
- Watchers: 10
- Forks: 8
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# babel-plugin-filter-imports
[](https://travis-ci.org/ember-cli/babel-plugin-filter-imports)
[](https://www.npmjs.com/package/babel-plugin-filter-imports)
This babel plugin is used to removed references to imports within a module. This can be useful for removing debugging statements when doing a production build of your code. It is often used in conjunction with other tools like Uglify that perform dead code elimination.
## Installation
```sh
$ yarn add --dev babel-plugin-filter-imports
```
*This plugin is for Babel 7. If you need to support:*
- *Babel 6 use the [babel6](https://github.com/ember-cli/babel-plugin-filter-imports/tree/babel6) branch*
- *Babel 5 use the [v0.2.x](https://github.com/ember-cli/babel-plugin-filter-imports/tree/v0.2.x) branch*
## Example
Given the `.babelrc`
```json
{
"plugins": [["filter-imports", {
"imports": {
"debugging-tools": [ "warn" ]
}
}]]
}
```
the module
```js
import { warn } from 'debugging-tools';
function join(args, sep) {
if (arguments.length > 2) {
warn("join expects at most 2 arguments");
}
return args.join(sep);
}
```
will be transformed to
```js
function join(args, sep) {
if (arguments.length > 2) {
}
return args.join(sep);
}
```
## Configuration
- `options[keepImports]` `[Boolean]`: An flag that indicates imports removal from header.
- `options[imports]` `[Object]`: An object whose keys are names of modules.
- `options[imports][moduleName]` `[String]`: An array of names of imports from `moduleName` to be removed. You can include `'default'` for default export and `'*'` for a namespace export.
## Upgrade to `1.x`/`2.x`
There were breaking changes in the plugin configuration, you must update it to work correctly.
##### Before `1.x`
```json
{
"plugins": [["filter-imports", {
"debugging-tools": [ "warn" ]
}]]
}
```
##### After
```json
{
"plugins": [["filter-imports", {
"imports": {
"debugging-tools": [ "warn" ]
}
}]]
}
```