-->

how to include a private local file in javascript

2020-07-02 10:58发布

问题:

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

I am have the following 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 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.json and bower finds the file from the cache?

回答1:

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

"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.



回答2:

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

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


回答3:

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


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