0

我正在制作 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 文件夹中时 - 我在网络检查器中看到它无法从那里加载“es6-modules-loader@0.16.6.js”,所以我从 Internet 下载了该文件并将它在“lib”文件夹中。然后一切正常:)

但:

今天网络连接停止了一段时间,我无法运行该项目,因为它实际上从网上加载了两个文件:

https://github.jspm.io/jmcriffey/bower-traceur@0.0.87.js
https://github.jspm.io/jmcriffey/bower-traceur@0.0.87/traceur.js

我看到它们在 system.js 的末尾定义。

所以我的问题是:我怎样才能从本地文件系统加载所有内容?

4

1 回答 1

0

这是我的设置,希望对你有用

我通过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 文件,因此您必须在 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
});

这是我的设置,不一定是最好的,但它对我有用。

我希望它对你有帮助。

于 2015-08-20T14:19:14.487 回答