【问题标题】:Adding npm libraries to Angular2 (v2.0.0-rc.1) app将 npm 库添加到 Angular2 (v2.0.0-rc.1) 应用程序
【发布时间】:2016-06-11 22:19:20
【问题描述】:

我目前正在努力将 npm 库引入我的 Angular2 应用程序(特别是 https://github.com/manfredsteyer/angular2-oauth2)。

当我尝试将库导入我的应用程序时,我收到 404。如果我将库添加到我的 systemjs.config.js mappackages 部分,我只是为库的依赖项获得 404。添加这些依赖项后,我会为每个依赖项的依赖项(等等)获得 404。

我还向 GitHub 存储库添加了一个类型映射:

"dependencies": {
  "angular2-oauth2": "github:manfredsteyer/angular2-oauth2/oauth-service.d.ts#0a0d321"
}

我在这里错过了什么?

【问题讨论】:

    标签: angular npm


    【解决方案1】:

    您需要在 SystemJS 配置中配置库及其依赖项:

    var map = {
      'app': 'app', // 'dist',
      '@angular': 'node_modules/@angular',
      'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
      'rxjs': 'node_modules/rxjs',
      'angular2-oauth2': 'node_modules/angular2-oauth2',
      'base64-js': 'node_modules/base64-js/lib/b64.js',
      'sha256': 'node_modules/sha256/lib/sha256.js',
      (...)
    };
    

    这是一个带有 Webpack 的示例应用程序:https://github.com/manfredsteyer/angular2-rc1-sample

    【讨论】:

    • 意味着每个库的所有依赖项都需要显式声明吗?这不是在一定程度上消除了 npm 的用处吗?
    • 事实上,我们在前端应用程序的上下文中使用 NPM。在这种情况下(使用 SystemJS),我们需要在 node_modules 文件夹中配置模块名称和实际 bundle 之间的关系...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 2017-01-01
    • 2016-09-15
    相关资源
    最近更新 更多