Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

babel-plugin-remove-unused-import

chuyik87MIT2.1.1

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

imcuttle, shake, remove-unused, babel-plugin

readme

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

  • <input checked="" disabled="" type="checkbox"> Supporting Scope

changelog

2.1.1 (2021-01-04)

Bug Fixes

  • source.node.loc might be empty (44b8b98)

2.1.0 (2021-01-04)

Features

2.0.0 (2019-09-09)

Features

  • core: use scope for more smarter removing (d6befc6), closes #4

1.1.2 (2019-03-13)

Bug Fixes

  • toString named in runtimeData (1a97593)

1.1.1 (2018-11-06)

Bug Fixes

  • computed value in ObjectProperty / class methods (3ab6e2d)

1.1.0 (2018-11-05)

Features

  • supporting ObjectProperty (5f822a4)

1.0.13 (2018-02-09)

1.0.12 (2018-02-08)

1.0.11 (2018-02-06)

1.0.10 (2018-02-05)

1.0.9 (2017-12-21)

1.0.7 (2017-11-29)

1.0.6 (2017-11-29)

1.0.5 (2017-11-29)

1.0.4 (2017-11-29)

1.0.3 (2017-11-29)

1.0.2 (2017-11-29)

1.0.1 (2017-11-29)