避免加载所有javascripts文件

时间:2016-08-15 12:12:52

标签: javascript typescript asp.net-core rxjs5

我在打字稿中使用rxjs:

import {Observable} from "./rx/Rx"

var main = () => {

  $(".ui.dropdown").dropdown();
  $(".left-half").backstretch(["../images/lotus.jpg"]);

  var source = Observable.range(0, 3);


  var subscription = source.subscribe(
    x => {
      console.log("Next: ${x}");
    },
    err => {
      console.log("Error: ${err}");
    },
    () => {
      console.log("Completed");
    });

};

$(document)
  .ready(() => {
    main();
  });

和文件结构

enter image description here

问题是,typescript将其编译为多个文件而不是一个文件。 enter image description here

Everythings工作正常,但来自rxjs的所有脚本都将加载为show:
enter image description here

要加载页面,需要 25.42s ,这太可怕了。我只使用Observable对象,将加载所有库。

如何防止长时间装载?

更新 对于后端,我使用的是ASP.NET Core,tsconfig文件如下所示:

{
  "compilerOptions": {
    "module": "amd",
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es6",
    "outDir": "../wwwroot/js"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

使用了require.js(布局模板):

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>@ViewData["Title"] - IndustryCloud</title>

  <environment names="Development">
    <link href="~/lib/sui/semantic.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/css/site.css" />
  </environment>

  <environment names="Staging,Production">
    <link href="~/lib/sui/semantic.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/css/site.css" />
  </environment>

</head>
<body>

  @RenderBody()

  <environment names="Development">
    <script src="~/lib/jquery/jquery.js"></script>
    <script src="~/lib/jquery-backstretch/jquery.backstretch.js"></script>
    <script src="~/lib/sui/semantic.js"></script>
    <script src="~/lib/require/require.js" data-main="../js/signin.js"></script>
  </environment>

  <environment names="Staging,Production">

  </environment>

</body>
</html>

0 个答案:

没有答案