import * as at from '../../../at-angular'
我更希望做...
import * as at from 'fv/at-angular'
我的src
目录是fv
,所以我的应用程序文件夹结构如下:
- src
- at-angular.ts
- core
- services
....
我是否可以通过某种方式使typescript中的fv
指向src
?
import * as at from '../../../at-angular'
我更希望做...
import * as at from 'fv/at-angular'
我的src
目录是fv
,所以我的应用程序文件夹结构如下:
- src
- at-angular.ts
- core
- services
....
我是否可以通过某种方式使typescript中的fv
指向src
?
TypeScript 1.8(尚未发布)将具有路径映射功能:
这可能是你正在寻找的内容。Path mappings
Sometimes modules are not directly located under baseUrl. It is possible to control how locations are computed in such cases using path mappings. Path mappings are specified using the following JSON structure:
{ "paths": { "pattern-1": "substitution" | ["list of substitutions"], "pattern-2": "substitution" | ["list of substitutions"], ... "pattern-N": "substitution" | ["list of substitutions"] } }
Patterns and substitutions are strings that can have zero or one asteriks ('*'). Interpretation of both patterns and substitutions will be described in Resolution process section.
/**
* Assuming the following project structure
* /src
* /app
* /services
* /models
* /node_modules
* .webpack.config.js
* tsconfig.json
*/
var path = require('path');
module.exports = {
module: { ... },
devtool: '...',
resolve: {
modules: [
path.resolve('./node_modules'),
path.resolve('./app')
]
}
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"*",
"app/*"
]
}
}
这是我的设置,它可以正常工作。只需构建,当您想要在dist目录中使用node运行代码时,您必须传递NODE_PATH=dist。
将此脚本添加到您的package.json脚本中并运行它以测试一切是否正常工作。
"build-test": "NODE_PATH=dist node --inspect dist"
我已经为源代码创建了一个Gist,以使用绝对路径或在tsconfig.json中定义的任何其他路径。 它与Browserify+Watchify+Tsify很好地配合,也适用于Gulp-typescript。
https://gist.github.com/azarus/f369ee2ab0283ba0793b0ccf0e9ec590
它将tsconfig.json中定义的路径名称和baseUrl转换为相对路径名称。 享受吧!