我的项目结构如下
dist
|- src
| |- s.js
|- test
|- t.js
node_modules
results
|- r.json
src
|- s.ts
test
|- t.ts
tsconfig.json
typings.d.ts
s.ts 导入 r.json ,如下所示:
import * as results from '../results/r.json';
显然,这在编译后不起作用,因为结果现在是两个文件夹...
解决此问题的正确方法是什么?以下是我的 tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"inlineSourceMap": true,
"lib": [
"dom",
"es2015"
],
"moduleResolution": "node",
"outDir": "dist/",
"target": "es5",
"typeRoots": [
"node_modules/@types",
"./typings.d.ts"
]
},
"include": [
"src/**/*.ts",
"results/r.json",
"test/**/*.ts",
"./typings.d.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
答案 0 :(得分:1)
最好的方法是完全避免这种情况。尝试使深度级别匹配。
e.g:
root
dist-es5
index.ts
index.spec.ts
src
index.ts
index.spec.ts
至于保持测试/规范代码不被分发,您可以拥有多个tsconfig.json
例如你可以看一下:Setting up tsconfig with spec/test folder