井号(#)是否在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.
所引用的文件名似乎来自另一个NPM模块,这意味着他们知道自己在做什么.因此,当我转到app / min-libs / node_modules / grunt-contrib-jshint / node_modules / jshint / node_modules / cli / examples / cat.js时,令人反感的行说:
#!/usr/bin/env node
这是评论,还是此NPM模块的所有者知道某些禁止使用超秘密的JavaScript技术?
解决方法:
它不是JavaScript技术,而是* nix OS.它称为shebang
.来自Wiki的报价.
Under Unix-like operating systems, when a script with a shebang is run
as a program, the program loader parses the rest of the script’s
initial line as an interpreter directive; the specified interpreter
program is run instead, passing to it as an argument the path that was
initially used when attempting to run the scrip
因此,可以在外壳程序中执行cat.js文件,就像可执行文件一样(如果它具有可执行文件许可权).
cat.js
代替
node cat.js