tyescript中的rootDir和baseUrl有什么区别?
根据 ts 文档
基本网址
Base directory to resolve non-relative module names. See Module Resolution documentation for more details.
Run Code Online (Sandbox Code Playgroud)
和根目录
Specifies the root directory of input files. Only use to control the output directory structure with --outDir.
Run Code Online (Sandbox Code Playgroud)
在我的 tsconfig 中,我添加了 "baseUrl": "app/javascript/src",
并且没有添加任何内容
rootDir
Run Code Online (Sandbox Code Playgroud)
那是对的吗?(这有效,但我不确定这是否正确)
更新: rootDir 给我错误,因为我使用的是绝对路径
这是我的 tsconfig。(baseUrl 没有)
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es6",
"dom"
],
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"jsx": "react",
"target": "es5",
"allowSyntheticDefaultImports": true,
"baseUrl": "app/javascript/src",
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true,
"skipLibCheck": true,
"allowJs": true,
"strict": true,
"outDir": "app/javascript/.dist",
},
"exclude": [
"node_modules",
"**/*.js",
"**/.jsx"
],
"include": [
"**/*.ts",
"**/*.tsx"
],
"compileOnSave": false
}
Run Code Online (Sandbox Code Playgroud)
在 webpack 中,我正在解析这样的路径
resolved_paths: ['app/javascript/src', 'app/javascript']
Run Code Online (Sandbox Code Playgroud)
bas*_*rat 10
我添加了“baseUrl”:“app / javascript / src”,这是正确的吗?
否。如果您正在为您的项目指定包含的文件(如 所示src),您应该使用rootDir(如所述Specifies the root directory of input files.)。
baseUrl仅对非相对导入有效。您的代码大多具有相对导入,例如,import something from './something'因此它不会对您产生任何不利影响。
| 归档时间: |
|
| 查看次数: |
12655 次 |
| 最近记录: |