index.js没有做index.ts做的事

index.js not doing what index.ts does

本文关键字:index ts js      更新时间:2024-05-04

我目前正在用angular2和typescript构建一个网络应用程序。我尝试使用index.ts,所以在我的代码中,我可以简单地使用

import {LayoutComponent} from '../layout';

但是当我进行transfile时,javascript引擎不会查找index.js,而是查找./layout,所以它不起作用。

是否有typescript transplaner的配置,我应该用systemjs或使用其他类似webpack的加载程序来配置它?

我找到了原因。Typescript使用的是nodejs模块解析,如下所述:http://www.typescriptlang.org/docs/handbook/module-resolution.html

但是systemjs不使用nodejs分辨率。因此,我需要使用./layout/index与systemjs模块分辨率兼容,或者为每个模块使用映射条目。但是commonjs确实使用nodejs分辨率,所以我将转换到commonjs并使用webpack。

是的,需要配置systemjs

你应该在你的index.html文件中有这样的东西:

  System.config({
    packages: {
      src: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
    System.import('src/dist/boot') --- your path to root file
        .then(null, console.error.bind(console));

在Angular2文档页面上,您可以找到一个五分钟的快速入门教程,按照该教程进行操作,之后,您可以按照自己的意愿自定义应用程序:https://angular.io/guide/quickstart