无法以commonjs方式运行angular2

时间:2016-07-14 01:56:27

标签: typescript angular gulp commonjs

首先,我不知道package.json中@angularangular2之间的区别。 但我喜欢package.json中的angular2方式。 这是我的github source

问题在于我无法改变" system" to" commonjs"在tsconfig_c.json中,否则angular2将抛出我无法理解的错误。

HTML:

<!DOCTYPE html>
<html>
<!-- #docregion head -->
<!-- #docregion base-href -->

<head>
  <base href="/" />
  <!-- #enddocregion base-href -->
  <title>Angular 2 Seed</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- #docregion css -->
  <link rel="stylesheet" href="styles.css">
  <!-- #enddocregion css -->

  <!-- 1. Load libraries -->
  <script src="libs/angular2-polyfills.js"></script>
  <script src="libs/system.src.js"></script>
  <script src="libs/Rx.js"></script>
  <script src="libs/angular2.dev.js"></script>
  <script src="libs/router.dev.js"></script>

  <!-- 2. Configure SystemJS -->
  <script>
      System.config({
        packages: {        
          app: {
            format: 'register',
            defaultExtension: 'js'
          }
        }
      });
      System.import('app/bootstrap')
            .then(null, console.error.bind(console));
    </script>
</head>
<!-- 3. Display the application -->

<body>
  <my-app>Loading...</my-app>
</body>

</html>

配置:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },
  "exclude": [
    "node_modules"
  ]
}

如果编译&#34;系统&#34;一切都很好。但我更喜欢&#34; commonjs&#34;办法。 有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

正如@Sanket所说,angular2包是Angular 2的旧测试版。关于你的问题,如果你在commonjs编译,你必须告诉SystemJs你的应用程序在{{} 1}},所以你必须改变commonjs配置:

index.html