使用SystemJS和ES导入语法时,导入Angular2组件时遇到问题。SystemJS和ES模块导入的相对路径
项目结构:
ROOT
|_src
|_client
|_app
|_frameworks
|_il8n
|_analytics
|_main
|_components
|_pages
|_utility
比方说,我有一个文件:ROOT/src/client/app/frameworks/il8n/language-service.ts
和另一个文件:ROOT/src/client/app/main/pages/login/login.ts
。在login.ts我想导入language.ts,这样做的一个方法是,像这样:
//login.ts import { LanguageService } from '../../../../frameworks/il8n/language-service';
另一种方式来做到这一点,利用桶,就像这样:
//login.ts import { LanguageService } from '../../../../frameworks/index';
其中frameworks/index.ts
做export * from './il8n/language-service';
我不想做../../../
等我每次需要进口一些时间;这将是很好,如果我可以做import { LanguageService } from 'frameworks';
到目前为止,我已经能够让我的构建过程中使用SystemJS的"map" option像这样的工作:
map: {
frameworks: 'src/client/app/frameworks/index',
components: 'src/client/app/main/components/index',
pages: 'src/client/app/main/pages/index'
}
然而,我的IDE抱怨(所有的智能感知功能完全打破),只要我做这样的事情:
`import { LanguageService } from 'frameworks';`
这里是我的tsconfig.json文件:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"baseUrl": "./src",
"paths": {
"frameworks": ["client/app/frameworks"],
"components": ["client/app/main/components"],
"pages": ["client/app/main/pages"],
"utility": ["client/app/main/utility"]
}
},
"compileOnSave": false
}
是否有一种方法可以同时满足我的IDE和SystemJS构建配置,以便我可以执行“简单”导入?
你使用哪个IDE版本? – anstarovoyt
我使用WebStorm 2016.2 – exk0730
可以请你分享你的项目吗?该功能必须适用于WS2016。2 – anstarovoyt