This is npm-mode, an Emacs minor mode for working with NPM projects.
The recommended way to install npm-mode is through the package manager and MELPA.
Start by cloning the npm-mode package repository:
$ git clone https://github.com/mojochao/npm-mode.git /your/path/here
Finish by loading the npm-mode package in your emacs configuration:
(add-to-list 'load-path "/your/path/here/npm-mode")
(require 'npm-mode)
The npm-mode package provides a minor mode which can be activated with:
(npm-mode)
The mode can be activated globally with:
(npm-global-mode)
The mode can be activated on a per-project basis using directory local
variables by running add-dir-local-variable
from the root directory
of a project.
For example, visit the README.md
file in the root directory of a
project, and run M-x add-dir-local-variable. Emacs will
prompt you for Mode or subdirectory:
, to which you should enter
nil
.
Next, you will be prompted for Add directory-local variable:
, to
which you should enter mode
.
Next, you will be prompted for Add mode with value:
, to which you
should enter npm-mode
.
Next, you will be placed in a new .dir-locals.el
buffer containing
the directory local variables for the project, including the added
npm-mode
configuration.
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((nil
(mode . npm)))
Finally, save the buffer contents with C-x C-s, and your
project is configured for npm-mode
.
Now when you visit any file under the project directory, npm-mode will be activated and its commands made available.
The mode provides a command keymap, whose default C-c n prefix can be configured with M-x customize-variable npm-mode-keymap-prefix.
Once npm-mode has been activated, its commands are accessed by the C-c n command prefix:
command | keymap | description |
---|---|---|
npm-mode-npm-init | n | Initialize new project |
npm-mode-npm-install | i | Install all project dependencies |
npm-mode-npm-install-save | s | Add new project dependency |
npm-mode-npm-install-save-dev | d | Add new project dev dependency |
npm-mode-npm-uninstall | u | Remove project dependency |
npm-mode-npm-list | l | List installed project dependencies |
npm-mode-npm-run | r | Run project script |
npm-mode-visit-project-file | v | Visit project package.json file |
? | Display keymap commands |
Running C-c n n will create a new project in the current directory.
Running C-c n i in a project directory will install all project dependencies.
Running C-c n s in a project directory will prompt for the name of a package to install and will install it as a project dependency.
Running C-c n d in a project directory will prompt for the name of a to install and will install it as a project dev dependency.
Running C-c n u in a project directory will prompt for the name of a package to uninstall and will uninstall it and remove it from project dependencies.
Running C-c n l in a project directory will list the project.
Running C-c n r in a project directory will prompt for the name of a script to run and will run it. Completion support is provided.
Running C-c n v in a project directory will visit the project file in a buffer.
This repo is a rewrite of a fork of https://github.com/AlexChesters/emacs-npm, and its history has been preserved. Many thanks to Alex for his contribution.