我正在尝试让npm在脚本文件夹上进行构建浏览器化。问题是,我在Windows上并且正在执行文件夹/*.js似乎不起作用。我尝试全局安装 glob,但每当我运行构建命令时,都会返回错误,说"找不到模块'c:\www\project\static\js\components*.js"。
这是我的包.json:
{
"name": "TEST",
"description": "ITS ME MARIO",
"author": "JJ",
"version": "0.0.1",
"dependencies": {
"connect": "1.8.5",
"express": "2.5.2",
"jade": "0.20.0",
"mongoose": "3.8.x",
"socket.io": "0.8.7"
},
"devDependencies": {
"vows": "0.5.x",
"mocha": "*",
"should": "*",
"jshint": "latest",
"browserify": "latest",
"rimraf": "latest",
"hashmark": "latest",
"stylus": "latest",
"glob": "latest"
},
"scripts": {
"clean": "rimraf dist",
"test": "mocha test/",
"build:components-js": "browserify static/js/components/*.js > static/dist/components.js",
"build:app-js": "browserify static/js/script > static/dist/app.js",
"build:css": "stylus static/css/style.styl > static/dist/main.css",
"build": "npm run build:css && npm run build:components-js && npm run build:app-js"
},
"engine": "node >= 0.6.6"
}
有人知道我做错了什么吗?
我不认为你做错了什么;这基本上是Windows shell/console/命令提示符的限制,尽管browserify可以"改进"以避开它并使用glob/node-glob代替。我不确定浏览器化,但jshint是类似的。
一些想法:
-
请尝试改为传递根目录名称。它的功能不那么强大,但似乎与
jshint
配合得很好:https://github.com/jshint/jshint/issues/1904 -
使用cygwin作为运行npm的shell。它为Windows带来了很多*nix功能。
-
调整或请求调整浏览器化(和jshint,和...?),以便它们调用glob库来处理这些与文件相关的参数。比较:https://github.com/jshint/jshint/issues/1998
-
包装说工具与"翻译器"这样的 https://www.npmjs.com/package/build-jshint.请注意,这是明确设计为支持
**
通配符等。
只是猜测,但也可能有一种方法可以
-
使用PowerShell(最新版本的Windows附带 - 请参阅
Get-ChildItem
命令) -
或者汉密尔顿 C shell (我认为使用
...
而不是**
),或者其他东西,作为你的 shell。 -
使用带
/r
循环递归到子文件夹中。我不建议这样做 - 特定于Windows,不是很可链接 - 但是如果我在我的package.json
文件中包含以下内容,下面设置的"wint"命令确实"有效"(使用npm run wint
调用)。
Windows 循环(注意:将下面的输出重定向到文件并不是一个简单的>
因为...do jshint %f > chk.txt
会覆盖自身,并且...do jshint %f > %f.chk.txt
可能会生成许多 chk.txt 文件撒在周围):
"scripts": {
"lint": "jshint **.js",
"wint": "for /r %f in (*.js) do jshint %f",
},
但是上面的命令通常不能跨平台使用。此外,使用替代 shell,默认情况下,您无法从文件夹和"在此处打开命令窗口"shift+right-click
中受益。
相关:
不能在 Windows 中使用 GLOB 和 JSHint?
https://superuser.com/questions/358863/wildcard-for-all-subdirectories-or-all-descendent-directories-in-windows-command