Windows NPM中的通配符 [英] Glob wildcards in windows npm

查看:70
本文介绍了Windows NPM中的通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让npm在脚本文件夹上进行浏览器构建.问题是,我在Windows上并且正在执行folder/*.js似乎不起作用.我已经尝试在全球范围内安装glob,但是每当我运行构建命令时,错误都会再次返回找不到模块'c:\ www \ project \ static \ js \ components * .js'.

I'm trying to get npm to do a build browserify on a folder of scripts. The problem is, I'm on windows and doing folder/*.js doesn't seem to work. I've tried globally installing glob, but whenever I run a build command, the error comes back saying "Cannot find module 'c:\www\project\static\js\components*.js'.

这是我的package.json:

Here's my 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"
}

有人知道我在做什么错吗?

Anyone know what I'm doing wrong?

推荐答案

我认为您没有做错任何事情;这基本上是Windows Shell/控制台/命令提示符的限制,尽管可以改进" browserify来回避此问题,而改用glob/node-glob.我不确定关于browserify,但jshint与此类似.

I don't think you're doing anything wrong; this is basically a limitation of the Windows shell/console/command prompt, although browserify could be 'improved' to sidestep that and use glob / node-glob instead. I'm not sure about browserify, but jshint is similar.

一些想法:

  • Try passing the root directory name instead. That's less powerful but seems to work well enough with jshint: https://github.com/jshint/jshint/issues/1904

使用cygwin作为运行npm的外壳.它为Windows带来了很多* nix功能.

Use cygwin as the shell you run npm from. It brings much *nix power to Windows.

调整或请求调整以浏览器化(以及jshint和...?),以便它们调用glob库来处理这些与文件相关的参数.比较: https://github.com/jshint/jshint/issues/1998

Tweak or request a tweak to browserify (and jshint, and... ?) so that they invoke the glob library to handle these file-related parameters. Compare: https://github.com/jshint/jshint/issues/1998

用翻译器"包装所说的工具,例如 https://www.npmjs. com/package/build-jshint .请注意,这是专门设计为支持**通配符等.

Wrap said tools with 'translators' such https://www.npmjs.com/package/build-jshint . Note that this is explicitly designed to support ** wildcards etc.

只是猜测,但也许还有一种方法

Just guessing, but there might also be a way to

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

或Hamilton C外壳程序(我认为使用...而不是**)或其他内容作为您的外壳程序.

or Hamilton C shell (uses ... instead of **, I think), or something else, as your shell.

使用带有/r的循环递归到子文件夹.我不建议这样做-特定于Windows,不是很容易链接-但如果在我的package.json文件中包含以下内容,则下面设置的'wint'命令可以正常工作(用npm run wint调用).

use a loop with /r for recursing into subfolders. I'm not recommending this--Windows-specific, not very chainable--but the 'wint' command set up below does 'work' (invoke with npm run wint) if I include the following in my package.json file.

循环(注意:将下面的输出重定向到文件不是简单的>,因为...do jshint %f > chk.txt会覆盖自身,并且...do jshint %f > %f.chk.txt可能会产生许多散落的chk.txt文件):

loop for Windows (Note: redirecting the output below to a file isn't a simple > because ...do jshint %f > chk.txt will overwrite itself and ...do jshint %f > %f.chk.txt may generate many chk.txt files sprinkled around):

"scripts": {
  "lint": "jshint **.js",
  "wint": "for /r %f in (*.js) do jshint %f",
},

但是上面的命令通常不能跨平台使用.另外,使用替代外壳程序,默认情况下,您不能从能够在文件夹上单击shift+right-click并在在此处打开命令窗口"中受益.

But the commands above would generally not be usable cross-platform. Also, using an alternative shell, you don't benefit by default from being able to shift+right-click on a folder and "Open command window here".

相关:

https://superuser.com/questions/358863/wildcard-for-all-subdirectories-or-all-descendent-directories-in-windows-command

这篇关于Windows NPM中的通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆