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.
$ yarn add --dev babel-plugin-filter-imports
This plugin is for Babel 7. If you need to support:
Given the .babelrc
{
"plugins": [["filter-imports", {
"imports": {
"debugging-tools": [ "warn" ]
}
}]]
}
the module
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
function join(args, sep) {
if (arguments.length > 2) {
}
return args.join(sep);
}
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 frommoduleName
to be removed. You can include'default'
for default export and'*'
for a namespace export.
There were breaking changes in the plugin configuration, you must update it to work correctly.
{
"plugins": [["filter-imports", {
"debugging-tools": [ "warn" ]
}]]
}
{
"plugins": [["filter-imports", {
"imports": {
"debugging-tools": [ "warn" ]
}
}]]
}