我正在制作 Angular2 应用程序,主要的 HTML 是这样的:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>App</title>
<script src="./lib/traceur-runtime.js"></script>
<script src="./lib/system.js"></script>
<script src="./lib/angular2.dev.js"></script>
</head>
<body>
<app></app>
<script src="./js/bootstrap.js"></script>
</body>
</html>
我的目标是使所有文件在本地加载。因此,当我将这三个文件放入 lib 文件夹时,我在网络检查器中看到它无法加载”[电子邮件受保护] /cdn-cgi/l/email-protection”从那里,所以我从互联网下载了该文件并将其放入“lib”文件夹中。然后一切正常:)
BUT:
今天网络连接停止了一段时间,我无法运行该项目,因为它实际上从网络上加载了两个文件:
https://github.jspm.io/jmcriffey/[email protected] /cdn-cgi/l/email-protection
https://github.jspm.io/jmcriffey/[email protected] /cdn-cgi/l/email-protection/traceur.js
我看到它们在 system.js 的末尾定义。
所以我的问题是:如何从本地文件系统加载所有内容?
这是我的设置,希望对你有用
我通过安装了所有这些软件包npm
.
<script src="node_modules/traceur/bin/traceur-runtime.js"></script>
<script src="node_modules/systemjs/dist/system.js"></script>
<!-- alpha35 -->
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
简单地说,systemjs 将无法找到任何 angular2 文件,因此您必须添加paths https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#paths在 System.config 中告诉 systemjs angular2 的文件在哪里。
System.config({
traceurOptions: {
annotations: true,
types: true,
memberVariables: true
},
paths: {
'angular2/*' : 'node_modules/angular2/*'
},
defaultJSExtensions: true // or you specify the .js
});
这是我的设置,不一定是最好的设置,但它对我有用。
我希望它对你有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)