简体   繁体   English

将Javascript库添加到angular-brunch-seed

[英]Add a javascript library to angular-brunch-seed

I clone angular-bunch-seed on my computer https://github.com/scotch/angular-brunch-seed 我在计算机上克隆了angular-bunch-seed https://github.com/scotch/angular-brunch-seed

And I want to add breezejs to my project http://learn.breezejs.com/ 我想将breezejs添加到我的项目中http://learn.breezejs.com/

I copied the breeze libraries into my vendor folder /vendor/breeze/ 我将微风库复制到我的供应商文件夹/ vendor / breeze /

And then I changed the config.coffee file as follow: 然后,我将config.coffee文件更改如下:

exports.config =
  # See docs at http://brunch.readthedocs.org/en/latest/config.html.
  conventions:
    ignored: /(^vendor\/.*\.less$)|(^|\/)node_modules\/|(^|\/)_/
    assets: /^app\/assets\//
  modules:
    definition: false
    wrapper: false
  paths:
    public: '_public'
  files:
    javascripts:
      joinTo:
        'js/app.js': /^app/
        'js/vendor.js': /^vendor/
        'test/scenarios.js': /^test(\/|\\)e2e/
      order:
        before: [
          'vendor/console-polyfill/index.js'
          'vendor/jquery/jquery.js'
          'vendor/breeze/breeze.debug.js'
          'vendor/breeze/q.js'
          'vendor/angular/angular.js'
          'vendor/angular-resource/angular-resource.js'
          'vendor/angular-cookies/angular-cookies.js'
          'vendor/angular-sanitize/angular-sanitize.js'
          'vendor/bootstrap/docs/assets/js/bootstrap.js'
        ]

    stylesheets:
      joinTo:
        'css/app.css': /^(app|vendor)/
      order:
        before: [
          'app/styles/app.less'
        ]

    templates:
      joinTo: 
        'js/dontUseMe' : /^app/ # dirty hack for Jade compiling.

  plugins:
    jade:
      pretty: yes # Adds pretty-indentation whitespaces to output (false by default)
    jade_angular:
      modules_folder: 'partials'
      locals: {}

    bower:
      extend:
        "bootstrap" : 'vendor/bootstrap/docs/assets/js/bootstrap.js'
        "angular-mocks": []
        "styles": []
      asserts:
        "img" : /bootstrap(\\|\/)img/
        "font": /font-awesome(\\|\/)font/


  # Enable or disable minifying of result js / css files.
  # minify: true

And when i execute brunch build, check the vendor.js file.. no breeze library included! 当我执行早午餐构建时,请检查vendor.js文件..不包括微风库! What am i missing? 我想念什么?

PS: When I remove angular.js from the build file, it's properly removed. PS:当我从构建文件中删除angular.js时,它已被正确删除。

Well, the answer has easy and complex subparts. 好吧,答案有简单而复杂的子部分。

The easy part: why it does not work. 最简单的部分:为什么它不起作用。 angular-brunch-seed makes use of the bower-brunch package, which internally checks for component.json files in the vendor libraries. angular-brunch-seed使用bower-brunch软件包,该软件包在内部检查供应商库中的component.json文件。 That means that if you did not download the library using bower , or place the required component.json at the library's root (and a mention in the root component.json ), it will not be recognized as a proper vendor library and get ignored in the config.coffee 's joinTo regular expression. 这意味着,如果你没有使用下载库凉亭 ,或将在库的根所需的component.json(以及根component.json一提),它不会被认为是合适的供应商库,并会被忽略config.coffeejoinTo正则表达式。

The order part of this config.coffee file only manages the order of placement of your libraries in the generated vendor.js file; config.coffee文件的顺序部分仅管理库在生成的vendor.js文件中的放置顺序。 if that library gets ignored beforehand, the order line has no influence. 如果该库事先被忽略,则订单行没有影响。

Tricky part: get breeze into your vendor libraries. 棘手的部分:轻松进入您的供应商库。 The clean way should be to download it using bower. 干净的方法应该是使用Bower下载它。 Thing is, there is as of today no bower package for breeze, as you might have guessed. 事实是,到目前为止,您可能已经猜到没有凉亭。

[victor@M]<~> bower search breeze
No results
[victor@M]<~> bower search | \grep breeze
No results

That means that you'll have to create it yourself. 这意味着您必须自己创建它。 As explained in the bower docs , you'll have to package the bower final library files (not the sources) and a component.json in a git endpoint (github for instance) under some name (say, bower-breeze ) and register it to bower using bower register . bower docs中所述,您必须以某种名称(例如bower-breeze )将Bower最终库文件(而非源文件)和component.json打包到git端点(例如github)中并进行注册。用bower register Take a look at what angular guys did , for inspiration. 看看有角度的人做了什么,以寻求启发。 You will also have to include semver tags in that repository to match the versions of the base library. 您还必须在该存储库中包含semver标记以匹配基础库的版本。 Alternatively, you could open an issue on breeze's github and ask for a component.json to be included in their repository (or better yet, write it and file a pull request). 或者,您可以在微风的github上打开一个问题,并要求将component.json包含在其存储库中(或者更好的是,编写并提交拉取请求)。

Last measure, you may try to just write the component.json in your vendor directory and check if it still gets ignored, but I did not test that. 最后一种措施,您可以尝试只在您的供应商目录中写入component.json并检查它是否仍然被忽略,但是我没有对此进行测试。 Could work (but it's a hack) Maybe you would have to at least add a mention of it in angular-brunch-seed's root component.json too (with version info) 可以工作(但这是一个技巧)也许您也必须至少在angular-brunch-seed的根component.json中添加提及(带有版本信息)

To sum up, angular-brunch-seed is a tricky beast... 总而言之,角早午餐种子是一个棘手的野兽。

I followed your recommendations and sent a pull request to the Breeze team. 我遵循了您的建议,并向Breeze团队发送了请求请求。 After the pull request has been accepted, I will had the repo to bower if not done by them already. 拉取请求被接受后,如果他们还没有回购,我将进行回购。

for now I created a component.json file into my ./vendor/breeze folder 现在,我在./vendor/breeze文件夹中创建了一个component.json文件。

{
  "name": "breeze",
  "version": "1.2.9",
  "main": "./breeze.debug.js",
  "dependencies": {},
  "gitHead": "0b0891a13d0023bbfdf91785bd99ac5a416bf9c7",
  "_id": "BreezeS@1.2.9",
  "readme": "ERROR: No README.md file found!",
  "description": "ERROR: No README.md file found!",
  "repository": {
    "type": "git",
    "url": "git://github.com/IdeaBlade/Breeze.git"
  }
}

the gitHead is random.. but whatever, when I run brunch build, I can finally see breeze included into vendor.js ! gitHead是随机的..但是不管怎样,当我运行早午餐构建时,我终于可以看到vendor.js中包含了微风! Thx a lot 多谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM