Javascript 如何解析typescript导入以在节点_模块中查找库?
我有一个带typescript的Angular 2.4应用程序。 在我第一次尝试Angular 1时,我从未将节点模块推到测试环境中。只是推送了编译后的代码。但在Angular 2.4中,typescript从节点模块“导入”这些库。因此,当我将捆绑应用程序推送到测试环境时,它失败了,因为缺少节点模块 我是否必须将节点模块推送到测试环境中才能使其工作? 您如何将angular 2应用程序部署到非本地环境Javascript 如何解析typescript导入以在节点_模块中查找库?,javascript,angularjs,node.js,Javascript,Angularjs,Node.js,我有一个带typescript的Angular 2.4应用程序。 在我第一次尝试Angular 1时,我从未将节点模块推到测试环境中。只是推送了编译后的代码。但在Angular 2.4中,typescript从节点模块“导入”这些库。因此,当我将捆绑应用程序推送到测试环境时,它失败了,因为缺少节点模块 我是否必须将节点模块推送到测试环境中才能使其工作? 您如何将angular 2应用程序部署到非本地环境 谢谢大家! 不会从节点\模块导入应用程序的任何模块。在systemjs.config.js中
谢谢大家! 不会从节点\模块导入应用程序的任何模块。在systemjs.config.js中定义节点路径,然后使用您的应用程序。示例systemjs.config.js文件,并在任何组件中使用node_modules组件具有以下代码 systemjs.config.js
/**
* 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: '/Template/js/kpxl/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',
'primeng': 'npm:primeng',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// 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'
},
primeng: {
defaultExtension: 'js'
}
}
});
})(this);
任何组件
import { Component, OnInit, Input } from '@angular/core'
import { Http } from '@angular/http'
import { LazyLoadEvent, Button, Dialog } from 'primeng/primeng'
@Component({
selector: 'error-log',
moduleId: module.id,
templateUrl: '/Settings/ErrorLog.html'
})
export class ErrorLog implements OnInit {
}
正确绑定的应用程序在其运行所需的javascript文件中包含所有javascript代码。浏览器没有导入的概念,当然也不能访问磁盘上的node_modules目录,它也不应该这样做。捆绑代码中不存在原始ES6
import
语句。这取决于您是否使用System.js或其他模块加载程序/捆绑程序?谢谢Andy Ray!这是有道理的。但是index.html文件(如种子项目中所示)直接从节点模块引用了一些js文件,如shim.min.js、zone.js、system.src.js。这些问题将如何解决?