查看UglifyJS版本(此时尚未安装)
[root@localhost ~]# uglifyjs -v
-bash: uglifyjs: 未找到命令
[root@localhost ~]#
使用npm安装UglifyJS
[root@localhost src]# npm install uglify-js
added 1 package, and audited 2 packages in 11s
found 0 vulnerabilities
[root@localhost src]# cp node_modules/uglify-js/bin/uglifyjs /usr/local/bin/uglifyjs
把/usr/local/bin目录加入系统环境变量
[root@localhost ~]# vim /etc/profile
………………(此处省略内容若干)………………
export PATH=$PATH:/usr/local/bin
………………(此处省略内容若干)………………
[root@localhost ~]# source /etc/profile
查看UglifyJS版本
[root@localhost ~]# uglifyjs -v
uglify-js 3.17.4
[root@localhost ~]#
对demo.src.js文件进行压缩,并将压缩文件另存为demo.min.js
[root@localhost ~]# uglifyjs demo.src.js -c -m -o demo.min.js
参数说明:
-c:compression(压缩)
-m:mangle(混淆)
-o:输出文件