javascript - 使用 defaultExtension 为 systemjs 配置 Angular2 库

标签 javascript angular typescript npm systemjs

是否可以为 Angular2 设置一个 npm 存储库,自动处理默认扩展的 systemjs 配置?

我正在构建 ng2-orm 并且很好奇它在安装 npm 时是否可以自动运行。

我的 package.json 已经有一个“主要”定义,但没有默认扩展名。有没有一种方法可以自动执行此操作,以便在使用我的包时,实现者不需要为它们创建 systemjs.config.js 行?

这是我的 systemjs.config.js 文件,请参阅 ng2-orm 行,我必须手动添加它们。

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
      'ng2-orm': 'npm:ng2-orm'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      },
      'ng2-orm': {
        main: './dist/js/index.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

最佳答案

如果你想自动化 systemjs.config.js ,你想要的工具是 npm 模块 JSPM .您告诉它安装某些模块,它会安装这些模块并为您更新 package.json 和 systemjs.config.js。至少,那是梦想!

关于javascript - 使用 defaultExtension 为 systemjs 配置 Angular2 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39716781/

相关文章:

html - Angular 4中div背景图像的占位符

Angular5 PowerBI 嵌入不工作

javascript - Angular 6 event.stopPropagation() 在指令中不起作用(模板驱动形式已经采用 event.data)

javascript - 如何处理调用在 defer.resolve() 内返回 Promise 的函数?

javascript - 隐藏 Shield UI 图表的 X 轴

javascript - 打印每页页脚不重叠的多页 HTML 表格

javascript - 如何将一个日期框中的值复制到下一个日期框

javascript - 获取属性访问权限被拒绝 "document"

angular - 有什么方法可以将动态数据传递给 Angular 中的组件?

javascript - JavaScript Promise 中的可选 catch