是否可以为 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/