2014-09-24 2 views
1

Bower는 실제로 의존성을 해결하는 것 외에 어떤 일을합니까? 나는 그것이 사용되는 것이 의도 된 방법을 이해하기 위해 열심히 노력하고 있지만, 나는 몇몇 점들을 놓치고 있다고 생각한다 ...Bower는 자동으로 종속성을 설치하나요?

말, 나는 Bower 패키지 B에 의존하는 Bower 패키지를 가지고있다. 나는 패키지 A에 관심이 있습니다. 그게 바로 제가 사용하려고하는 것이기 때문입니다. 물론, 그것은 어떻게 든 패키지가 브라우저에로드되어 패키지 A가 작동 할 수 있어야 함을 의미합니다.

Bower를 사용하면 bower install a을 수행하고 bower_components에 두 패키지 A & B를 모두 찾을 수 있습니다. 지금까지, 굉장한.

하지만 지금은? 내가 자신을 (수동) A 과 B의 파일을 내 HTML 페이지에로드해야하는지 찾아야합니까? 나는 전체 bower_components이 웹을 통해 직접 액세스 할 수 있다고 생각하지 않으므로 관련 파일을 복사하기 위해 수동으로 내 Grunt (또는 무엇이든) 빌드 파일을 구성해야합니다.

무엇이 여기에 있습니까? 위의 내용이 사실이라면 Bower를 사용하여 암시 적 종속성을 모두 알아야 할 때 필요한 점은 무엇입니까?

답변

0

Bower는 종속성을 관리하며 --save (또는 -S) 플래그와 함께 사용하면 HTML에 올바른 파일을 추가합니다. index.html이 같은 디렉토리에 없으면 bower.json에 appPath를 설정해야합니다.

$ bower help install 

Usage: 

    bower install [<options>] 
    bower install <endpoint> [<endpoint> ..] [<options>] 
Options: 

    -F, --force-latest  Force latest version on conflict 
    -h, --help    Show this help message 
    -p, --production  Do not install project devDependencies 
    -S, --save    Save installed packages into the project's bower.json dependencies 
    -D, --save-dev   Save installed packages into the project's bower.json devDependencies 
    Additionally all global options listed in 'bower help' are available 

Description: 

    Installs the project dependencies or a specific set of endpoints. 
    Endpoints can have multiple forms: 
    - <source> 
    - <source>#<target> 
    - <name>=<source>#<target> 

    Where: 
    - <source> is a package URL, physical location or registry name 
    - <target> is a valid range, commit, branch, etc. 
    - <name> is the name it should have locally. 
``` 
0

실제로 아무 것도 누락하지 않았습니다. Bower는 의존성을로드하는 것을 다루지 않고 의존성을 설치합니다. 그들을로드하는 것은 당신이 스스로해야만하는 일입니다. 또한 사람들이 의존성을로드하는 다양한 방법이 많이 있습니다. 가장 일반적인 것은 아마도 Require.JS, Browserify (링크를 게시 할 크레딧이 너무 적음)이고 일반 스크립트는 index.html 페이지에 포함됩니다. 기본적으로 몇 가지 옵션이 있습니다.

  1. 로드 등록을 수동으로 처리 할 수 ​​있습니다. 즉, index.html 페이지에 <script src="..."></script> 태그를 추가하거나 Require.JS를 사용하는 경우 종속성에 대한 등록을 추가하고 app.js과 유사한 등록을 의미합니다. 이 단계는 전이 의존성 및 파일 경로를 파악하기 위해 수동으로 각 종속성을 확인하거나 설명서 또는 bower.json 파일을 읽어야한다는 것을 의미합니다.
  2. 일반 스크립트 인클루드를 사용하는 경우 을 사용하면 bower.json 종속 파일의 Wiredep 검사를 통해 자동으로 완료됩니다.
  3. RequireJS (또는 유사)를 사용하는 경우 Yeoman의 grunt-require-js에서 자동으로이 작업을 수행 할 수 있습니다.

2와 3 모두 라이브러리 작성자가 올바른 출력 파일을 제공함에 유의하십시오. 예 : 축소 된 버전을 원한다면 재정의를 선언하거나 명시 적으로 선언해야합니다.

"bower_components"에 대한 공개 액세스 권한은 가장 일반적인 접근 방법입니다. 접근을 막기 위해 어떤 것들이 있습니까?

0

저는 최근에 자신을 분만했습니다.그리고 내가 아는 한 짧은 대답은 : 예, bower는 종속성을 다운로드하려고합니다. 그러나 bower_components 디렉토리를 원하는대로 구성 할 수 있다는 것 외에는 설치된 구성 요소가 사용자가 편집하지 않는다는 아이디어가 있습니다. 당신이 수동으로 포함 할 경우 모두, 당신은

bower list --paths 

를 입력하고 이것은 당신이 (상대 URL에) 종속 관계에서 포함하는 데 필요한 모든 파일을 나열합니다.

원하는 파일을 원하는 경로로 복사 할 수있는 bower-installer (npm install -g bower-installer)을 사용할 수도 있습니다. 세밀한 컨트롤을 사용하거나 축소 된 버전을 선택하십시오.

다음은 출력 예입니다.

C:\Users\german\test>bower install bootstrap 
bower bootstrap#*   not-cached git://github.com/twbs/bootstrap.git#* 
bower bootstrap#*    resolve git://github.com/twbs/bootstrap.git#* 
bower bootstrap#*    download https://github.com/twbs/bootstrap/archive/v3.3.4.tar.gz 
bower bootstrap#*    extract archive.tar.gz 
bower bootstrap#*    resolved git://github.com/twbs/bootstrap.git#3.3.4 
bower jquery#>= 1.9.1  not-cached git://github.com/jquery/jquery.git#>= 1.9.1 
bower jquery#>= 1.9.1   resolve git://github.com/jquery/jquery.git#>= 1.9.1 
bower jquery#>= 1.9.1   download https://github.com/jquery/jquery/archive/2.1.4.tar.gz 
bower jquery#>= 1.9.1   extract archive.tar.gz 
bower jquery#>= 1.9.1   resolved git://github.com/jquery/jquery.git#2.1.4 
bower bootstrap#~3.3.4   install bootstrap#3.3.4 
bower jquery#>= 1.9.1   install jquery#2.1.4 

bootstrap#3.3.4 bower_components\bootstrap 
└── jquery#2.1.4 

jquery#2.1.4 bower_components\jquery 

C:\Users\german\test>bower list --paths 

    jquery: 'bower_components/jquery/dist/jquery.js', 
    bootstrap: [ 
    'bower_components/bootstrap/less/bootstrap.less', 
    'bower_components/bootstrap/dist/css/bootstrap.css', 
    'bower_components/bootstrap/dist/js/bootstrap.js', 
    'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot', 
    'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg', 
    'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf', 
    'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff', 
    'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2' 
    ] 

부트 스트랩 [] 쇼 모든 파일을

bower list --paths 

후 나는 bower_components에 따라 포함 할 필요가/부트 스트랩/bower.json 주 : [] 부분이 도움이

희망! 건배.

관련 문제