2.1.1 • Published 3 years ago

babel-plugin-remove-unused-import v2.1.1

Weekly downloads
8
License
MIT
Repository
github
Last release
3 years ago

babel-plugin-remove-unused-import

Fork from babel-plugin-danger-remove-unused-import

Fork Changes

  1. visitor.Program.enter -> visitor.Program.exit: make sure this plugin comes in after minify-dead-code-elimination.
  2. remove import binding.path.parentPath if not referenced, ignoring side effects.
  3. rename package to babel-plugin-remove-unused-import.

For shrinking the bundled javascript size :smile:

Note: remove unused import is dangerous because the imported package may have some side effects!

Option

{
  ignore: ['react']
}

Input

import React from 'react'
import Button from 'button'
import _ from 'lodash'
import moment from 'moment'
import { data } from '../some-where'

// ...

const a = {}
a.moment = <Button x={data} />

Output

import React from 'react'
import Button from 'button'
- import _ from 'lodash'
- import moment from 'moment'
import {data} from '../some-where'

// ...

const a = {}
a.moment = <Button x={data} />

Todo

  • Supporting Scope