rwe*_*eng 6 angularjs typescript systemjs jspm
因此,我在将jspm包导入typescript时发现的大多数示例都假设我想使用Systemjs在浏览器中加载和解释它们.但是,我宁愿使用tsc
构建commonjs模块并只导入js代码,因为在我看来,对我来说,这是更通用和反差的方法.
所以我的目录结构如下所示:
src/index.ts
jspm_packages/...
config.js
tsconfig.json
Run Code Online (Sandbox Code Playgroud)
使用tsconfig具有以下内容:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": false,
"rootDir": "src",
"outDir": "target/app",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true
},
"exclude": [
"jspm_packages",
"node_modules",
"typings",
"target"
]
}
Run Code Online (Sandbox Code Playgroud)
出于测试目的,我安装了角度2 jspm install npm:angular2
并试图在我的index.ts
通道中导入它import { bootstrap } from 'angular2/platform/browser';
运行时tsc
,我收到错误
src/index.ts(1,27): error TS2307: Cannot find module 'angular2/platform/browser'.
Run Code Online (Sandbox Code Playgroud)
现在我想知道,我可以使用打字稿知道jspm包吗?我觉得我尝试了一切,从tsconfig排除列表中删除了jspm_packages,切换到节点模块解析或systemjs模块生成.也许我还没找到合适的组合.关于下一步尝试的任何提示?
我也在努力解决同样的问题,经过一些研究,我了解到目前还没有好的解决方案来实现这一点。
解决方法:
A) 您可以复制依赖项并使用 npm 安装它。tsc 不应该抛出任何错误,因为它是从 npm 解析的。
B) 更改 tsconfig.json 并将 Angular 映射到 jspm 路径。例如
"baseUrl": ".",
"paths": {
"angular2/*": [
"jspm_packages/npm/angular2@2.0.0-beta.7/*"
],
"rxjs/*": [
"jspm_packages/npm/rxjs@5.0.0-beta.2/*"
]
}
Run Code Online (Sandbox Code Playgroud)
有关完整示例,请参阅https://github.com/frankwallis/plugin-typescript/tree/master/examples/angular2 。
请注意,“baseUrl”和“paths”不是官方属性,仅适用于打字稿编译器的测试版。
目前正在此处跟踪该问题: https ://github.com/Microsoft/TypeScript/issues/6012