try*_*sis 4 javascript comments npm jshint uglifyjs2
井号(#)是否在JavaScript中开始注释?我有一个正在与NPM一起使用的网站,当我尝试使用Grunt缩小JavaScript大小时,Uglify抛出了错误:
Warning: Uglification failed.
Unexpected character '#'.
Line 1 in app/min-libs/node_modules/grunt-contrib-jshint/node_modules/jshint/nod
e_modules/cli/examples/cat.js
Use --force to continue.
Run Code Online (Sandbox Code Playgroud)
所引用的文件名似乎来自另一个NPM模块,这意味着他们知道自己在做什么。因此,当我转到app / min-libs / node_modules / grunt-contrib-jshint / node_modules / jshint / node_modules / cli / examples / cat.js时,有问题的行说:
#!/usr/bin/env node
Run Code Online (Sandbox Code Playgroud)
这是评论,还是此NPM模块的所有者知道某些禁止使用超秘密的JavaScript技术?
它不是JavaScript技术,而是* nix OS。它被称为shebang。从维基报价
在类似Unix的操作系统下,当将带有shebang的脚本作为程序运行时,程序加载器会将脚本的其余首行解析为解释器指令。而是运行指定的解释器程序,将尝试运行脚本的最初使用的路径作为参数传递给它
因此,cat.js文件可以像可执行文件一样在外壳程序中执行(如果具有可执行文件权限)。
cat.js
Run Code Online (Sandbox Code Playgroud)
代替
node cat.js
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1144 次 |
| 最近记录: |