代码之家  ›  专栏  ›  技术社区  ›  drow

SystemJS、Typescript、angular2和模块化

  •  1
  • drow  · 技术社区  · 9 年前

    我正在尝试用angular2/systemjs/typescript和angular1一起使用的模块化编写基本应用程序,但遇到了一些问题。
    我需要这个东西在我的应用程序中的任何位置,而不依赖于文件的相对位置 smth-module 是我编写并包含的任何模块(导出) SmthCmp

    import SmthCmp from 'smth-module';
    

    测试应用程序结构

    ├── bootstrap.ts
    ├── graph-module
    │   ├── component
    │   │   └── line-graph
    │   │       └── line-graph.ts
    │   └── index.ts
    └── page-module
        ├── component
        │   └── page
        │       └── page.ts
        └── index.ts
    

    引导.ts

    ...
    import {PageCmp} from 'page-module/index';
    
    bootstrap(PageCmp, [
      ...
    ]);
    

    第ts页

    ...
    import {LineGraphCmp} from 'graph-module/index';
    
    ...
    export class PageCmp {}
    

    线粒度.ts

    ...
    export class LineGraphCmp {}
    

    图形和页面模块 索引 这样地

    export {PageCmp} from './component/page/page';
    

    也添加到 System.config()

    map: {
        'graph-module': '/graph-module',
        'page-module': '/page-module'
    }
    

    所以我可以使用 export Smth from 'module/index' 语法,这几乎就是我所需要的。但有一个问题

    app/bootstrap.ts(4,23): error TS2307: Cannot find module 'page-module/index'.
    app/page-module/component/page/page.ts(8,28): error TS2307: Cannot find module 'graph-module/index'.
    

    我如何告诉Typescript编译器有关这些模块的信息?或者我可以通过其他方式或模块系统实现模块的使用?
    我还可以用某种方式实现这种用法吗 import {PageCmp} from 'page-module' 没有直接“/index”引用?

    p、 这是我上一个问题的复制 this discussion

    1 回复  |  直到 9 年前
        1
  •  0
  •   drow    9 年前

    这个问题完全是关于我的问题。正在使用等待Typescript更新 moduleResolution: 'target' 用法

    https://github.com/Microsoft/TypeScript/issues/5039