How to install node modules globally?

假装没事ソ 提交于 2020-01-17 05:23:12

问题


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 ]


来源:https://stackoverflow.com/questions/38661930/how-to-install-node-modules-globally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!