【发布时间】:2016-06-17 03:54:56
【问题描述】:
所以我在将 jspm 包导入到 typescript 时发现的大多数示例都假设我想使用 Systemjs 在浏览器中加载和解释它们。但是,我更愿意使用tsc 来构建commonjs 模块并只导入js 代码,因为在我看来,这对我来说是更通用且抗错误的方法。
所以我的目录结构是这样的:
src/index.ts
jspm_packages/...
config.js
tsconfig.json
使用 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"
]
}
出于测试目的,我使用jspm install npm:angular2 安装了angular 2,并尝试通过import { bootstrap } from 'angular2/platform/browser'; 将其导入我的index.ts
运行tsc 时出现错误
src/index.ts(1,27): error TS2307: Cannot find module 'angular2/platform/browser'.
现在我想知道,我可以让 typescript 知道 jspm-packages 吗?我觉得我尝试了一切,从 tsconfig 排除列表中删除 jspm_packages,切换到节点模块解析或 systemjs 模块生成。也许我只是没有找到合适的组合。关于下一步要尝试什么的任何提示?
【问题讨论】:
-
jspm 网站的第一行是“jspm 是 SystemJS 通用模块加载器的包管理器,构建在动态 ES6 模块加载器之上”。我不认为在没有 system.js 的情况下使用 jspm 是正确的方法。
标签: angularjs typescript systemjs jspm