如何使用 bower 在 javascript 项目中包含私有本地文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18317105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:27:49  来源:igfitidea点击:

how to include a private local file in javascript project using bower

javascriptbower

提问by codeofnode

i want to include a custom file as one of the bower dependency.

我想包含一个自定义文件作为凉亭依赖项之一。

I am have the following bower.json

我有以下 bower.json

{
  "name": "xyz",
  "version": "0.0.0",
  "dependencies": {
    "sass-bootstrap": "~2.3.0",
    "requirejs": "~2.1.4",
    "modernizr": "~2.6.2",
    "jquery": "~1.9.1",
    "beautify": "file:/path/to/beautify.js"
  },

  "devDependencies": {}
}

But when i do bower install it gives error :

但是当我安装 bower 时,它给出了错误:

 bower beautify#*             ENOTFOUND Package file:/path/to/beautify.js not found

however when i open the same path in browser i get the right file. I have also checked the case sensitive of the path.

然而,当我在浏览器中打开相同的路径时,我得到了正确的文件。我还检查了路径的区分大小写。

Now can any one tell me what error i am doing? Is there any thing wrong with the syntax?

现在有人能告诉我我在做什么错误吗?语法有什么问题吗?

Also tell me what if i want to add the same via bower cache. Where the global bower cache is stored in mac? And how can we register the url of private package so that i just need to put name of the package in bower.jsonand bower finds the file from the cache?

还告诉我如果我想通过凉亭缓存添加相同的内容怎么办。mac 中全局 bower 缓存存储在哪里?我们如何注册私有包的 url,以便我只需要输入包的名称,bower.json然后 bower 从缓存中找到该文件?

采纳答案by Tijhaart

The code below didn't work for me using Bower 1.2.8 on Ubuntu.

下面的代码对我在 Ubuntu 上使用 Bower 1.2.8 不起作用。

"beautify": "/path/to/beautify.js"

"beautify": "/path/to/beautify.js"

What did work was using: "beautify": "./path/to/beautify.js". This way the path is pointing to the file relative from the directory where bower.json resides.

什么工作正在使用:"beautify": "./path/to/beautify.js"。这样,路径指向 bower.json 所在目录中的相对文件。

回答by Sheng

It should be just /relative/path/to/beautify.js. No 'file:/'.

它应该只是/relative/path/to/beautify.js。没有文件:/'。

"beautify": "/path/to/beautify.js"

回答by KeepCalmAndCarryOn

If you have bower installed you can do this from the commandline

如果您安装了凉亭,则可以从命令行执行此操作

bower install ../beautify.js -S

Assuming the local repo is a directory next to your current directory. This is just a testing approach and should be an available repo for general use

假设本地 repo 是当前目录旁边的目录。这只是一种测试方法,应该是通用的可用存储库



EDIT

编辑

It looks like you also need to tag your repo so you will pick up the latest changes too

看起来您还需要标记您的存储库,以便您也可以获取最新的更改

git tag v0.0.2