-->

How to install node modules globally?

2019-09-10 04:40发布

问题:

I have zero experience with npm other than knowing it exists. I believe I have managed to install uglify, but I have no idea how to use it. I had until recently been using Yuicompressor which had a java cli. How can I do something similar with uglify on a Windows 7 environment?

Unless there is a step I skipped, the command line tools details the arguements, but my attempts to try such fail.

https://github.com/mishoo/UglifyJS

C:\Data\Websites\local\htdocs\b>npm install uglify-js
uglify-js@2.7.0 node_modules\uglify-js
├── uglify-to-browserify@1.0.2
├── async@0.2.10
├── source-map@0.5.6
└── yargs@3.10.0 (decamelize@1.2.0, camelcase@1.2.1, window-size@0.1.0, cliui@2.
1.0)

C:\Data\Websites\local\htdocs\b>uglify
'uglify' is not recognized as an internal or external command,
operable program or batch file.

Anyone care to advise?

回答1:

Even though you installed the package uglify-js, to actually use it, it is: uglifyjs. So using your example, it would be something like:

C:\Data\Websites\local\htdocs\b>uglifyjs [ options... ] [ filename ]

Where options are parameters like: --compress, and a filename would be whatever JS file you want to uglify. e.g. uglifyjs --compress --mangle -- input.js



回答2:

To run it from the command line, you have to install it globally

C:\Data\Websites\local\htdocs\b>npm install uglify-js -g

Also, the name of the executable is uglifyjs

C:\Data\Websites\local\htdocs\b>uglifyjs


回答3:

There is a 'Usage' section on the repo's README.

uglifyjs [ options... ] [ filename ]