Running ImportJS in Emacs
- Install the
npm install import-js -g
- Configure ImportJS
- See Configuration
- Install import-js.el for Emacs
- Install via MELPA
- Alternatively, Copy plugins/import-js.el into your Emacs load-path and add
(require 'import-js)to your config. You will also need to install grizzl
- Run the import-js daemon
- The daemon will use watchman if installed to improve performance
- Import a file!
You can use something like
(M-x) import-js-importwith your cursor over the desired module
It will be helpful to bind
import-js-importto an easy-to-use binding, such as:
(define-prefix-command 'my-keymap) (global-set-key (kbd "s-a") 'my-keymap) (define-key my-keymap (kbd "a u") 'import-js-import)
- Go directly to a file
- The ImportJS goto interface allows us to jump to a package
(M-x) import-js-gotowill jump to the appropriate file found by ImportJS
- This should also be bound to something useful:
(global-set-key (kbd "<f4>") 'import-js-goto)
- Fix your imports
- Optionally, you can configure ImportJS to fix your imports for you, adding unknown variables and removing unused imports. ImportJS uses eslint to find these variables.
eslintmust be in your PATH.
- eslint plugins must be installed for that specific version of eslint (if eslint is a global eslint, you may need to install the plugins globally)
- Run with
- You can also configure
import-js-fixto run on save:
(add-hook 'after-save-hook 'import-js-fix)
Note on Node v6.1.0
I've had issues running import-js in Emacs on Node v6.1.0. Node >= v6.2.0 seems to work as expected.