windows中的全球通配符npm

use*_*508 7 glob node.js npm

我试图让npm在脚本文件夹上进行构建browserify.问题是,我在Windows上做文件夹/*.js似乎不起作用.我已尝试全局安装glob,但每当我运行构建命令时,错误都会回来说"找不到模块'c:\ www\project\static\js\components*.js'.

这是我的package.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"
}
Run Code Online (Sandbox Code Playgroud)

谁知道我做错了什么?

Jon*_*mbs 9

我不认为你做错了什么; 这基本上是Windows shell/console /命令提示符的限制,虽然browserify可以"改进"以回避它并使用glob/node-glob代替.我不确定browserify,但jshint是类似的.

一些想法:

只是猜测,但可能还有一种方法

  • 使用PowerShell(最新版​​本的Windows附带 - 请参阅Get-ChildItem命令)

  • 或者汉密尔顿C shell(...代替**,我认为)或其他东西,作为你的shell.

  • 使用循环/r来递归到子文件夹.我不推荐这个 - 特定于Windows,不是很可链接 - 但npm run wint如果我在我的package.json文件中包含以下内容,下面设置的'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",
},
Run Code Online (Sandbox Code Playgroud)

但是上面的命令通常不能跨平台使用.此外,使用备用shell,默认情况下您无法shift+right-click在文件夹和"打开命令窗口"中受益.

有关: