【发布时间】:2017-07-01 01:19:39
【问题描述】:
tl;dr : 模块解析不适用?
你好,
我正在玩 Typescript2 模块解析功能。
我注意到现在可以指定“路径”,以便您可以执行以下操作:
老办法
import {a} from "../../../foo"
新方式
import {a} from "services/foo"
为此,您需要在 tsconfig.json 中添加一些配置
"compilerOptions": {
"baseUrl": ".",
"paths": {
"services/*": ["./application/core/services/*"],
}
}
我遇到的问题是,在编译时,导入实际上并没有改变。我的 javascript 输出仍然包含来自“services/foo”的导入,因此在我的节点服务器上运行时显然会崩溃。
我使用 gulp-typescript 编译我的 javascript 文件:
var tsProject = ts.createProject("tsconfig.json");
return tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject()).js
.pipe(sourcemaps.write("../api"))
.pipe(gulp.dest(function(file) {
return file.base;
}));
我在这里完全迷失了,很想使用那个模块解析,这样我就可以摆脱那个 ../../ 地狱般的导入。任何帮助将不胜感激!
【问题讨论】:
标签: node.js typescript gulp typescript2.0 gulp-typescript