blog
blog copied to clipboard
typescript相关
tsconfig.json
{
"compilerOptions": {
"module": "esnext",
"target": "es6",
"lib": ["es6", "dom"],
"jsx": "preserve",
"moduleResolution": "node",
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src"
}
}
这是目前的配置,说明下:这里仅希望ts去做一些类型检查方面的工作,不涉及到其他的工作,如转换为低版本的语言等。因此ts转换后的目标代码仍然是es6的,且保留jsx,这部分的工作统一交给babel去做。相应的tsx的loader需要再走一遍babel-loader:
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'awesome-typescript-loader'
}
}
]
}
还有一点值得注意:baseUrl
Base directory to resolve non-relative module names. 配置这个之后写路径会方便很多,vscode可以完美支持,但是webpack要想支持还需如下配置:
resolve: {
...
plugins: [
new TsConfigPathsPlugin({
// 这里根据具体项目更改
baseUrl: path.resolve(__dirname, '../../../../../src')
})
]
},