如何用角CLI时添加第三方库? [英] How to add a third party library when using angular-cli?

查看:339
本文介绍了如何用角CLI时添加第三方库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试用角CLI( https://github.com创建一个角2应用/角度/角度-CLI 的),然后使用NG2材料( https://github.com / justindujardin / NG2材料)的UI组件。但我就是不明白如何/在哪里我必须包括以使用它NG2材料库。

I wanted to try out creating an Angular 2 app with angular-cli (https://github.com/angular/angular-cli) and then use ng2-material (https://github.com/justindujardin/ng2-material) for UI components. But I just don't understand how / where I have to include the ng2-material library in order to use it.

我创建了项目纳克新的myproject 然后我用启动服务器纳克服务,打开网页哪些刚刚制定了罚款。下一步,我安装NG2-材料 NPM安装NG2材料--save 。然后,我添加 MATERIAL_PROVIDERS 来角度的引导为如下所示的https://github.com/AngularShowcase/angular2-seed-ng2-material/blob/master/app/bootstrap.ts.

I created a project with ng new myproject then I started the server with ng serve and opened the webpage which just worked out fine. Next step, I installed ng2-material with npm install ng2-material --save. Then I added MATERIAL_PROVIDERS to angular's bootstrap as is shown here https://github.com/AngularShowcase/angular2-seed-ng2-material/blob/master/app/bootstrap.ts.

这将导致一个错误信息 GET HTTP://本地主机:4200 / NG2材料/所有404(未找到)在Web浏览器,我只是'吨找出如何摆脱它。

This results in an error message GET http://localhost:4200/ng2-material/all 404 (Not Found) in the web browser, and I just can't figure out how to get rid of it.

角CLI似乎是在做什么来创建一个 DIST -folder在一些是在使用节点模块的index.html结束了,但我看不出,或者是如何配置的。

angular-cli seems to be doing something to create a dist-folder where some of the node modules that are used in the index.html end up in, but I don't see where or how that's configured.

推荐答案

这为我工作:

烬-CLI-build.js ,您的依赖添加到的 vendorNpmFiles 的,例如

In the ember-cli-build.js, you add the dependency to the vendorNpmFiles, e.g.

module.exports = function (defaults) {
  var app = new Angular2App(defaults, {
      vendorNpmFiles: [
          'a2-in-memory-web-api/web-api.js'
      ]
  });
  return app.toTree();
}

(其中的 A2-内存的Web-API / WEB-api.js 的是在一个文件中我的 node_modules 的文件夹)

(where a2-in-memory-web-api/web-api.js is a file in my node_modules folder)

index.html的您添加以下行:

<script src="vendor/a2-in-memory-web-api/web-api.js"></script>

最后,您重新启动服务器。

Finally you restart your server.

未与角料进行测试,但你的想法。

Haven't tested it with angular material but you get the idea.

这篇关于如何用角CLI时添加第三方库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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