Angular2 + System.js - 让所有的文件本地加载 [英] Angular2 + System.js - make all files load locally

查看:929
本文介绍了Angular2 + System.js - 让所有的文件本地加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做Angular2应用程序,主要是HTML这样的:

I'm making Angular2 app, and the main HTML is this one:

<!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从那里看到的,所以我从网上下载互联网上的文件,并把它在lib目录文件夹中。然后,所有工作得很好:)

My goal is to make all files load locally. So - when I put those three files in the lib folder - I saw in the network inspector that it can't load "es6-modules-loader@0.16.6.js" from there, so I downloaded that file from Internet and put it in the "lib" folder. Then all worked fine :)

但是:

今天的网络连接停了一段时间,我不能运行该项目,因为它实际上是从网上下载两个文件:

Today the network connections stopped for a while, and I couldn't run the project, cause it actually loaded two more files from the net:

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月底定义。

I see them defined at the end of system.js.

所以我的问题是:怎样才能让一切加载从本地文件系统

So my question is: How can I make everything loads from the local filesystem?

推荐答案

这是我的设置,我希望它为你的作品

This is my set up, I hope it works for you

我安装了这所有的包通过 NPM

I installed all this packages through 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 来告诉到angular2的文件systemjs。

With simply this, systemjs will not be able to find any of the angular2 files, so you have to add paths in System.config to tell to systemjs where angular2's files are.

System.config({
    traceurOptions: {
        annotations: true,
        types: true,
        memberVariables: true
    },
    paths: {
       'angular2/*' : 'node_modules/angular2/*'
    },
    defaultJSExtensions: true // or you specify the .js
});

这是我的成立,不一定是最好的之一,但它为我工作。

This is my set up, not necessarily the best one, but it works for me.

我希望它可以帮助你。

这篇关于Angular2 + System.js - 让所有的文件本地加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆