未为 dev 编译子文件夹
Posted
技术标签:
【中文标题】未为 dev 编译子文件夹【英文标题】:Subfolders not being compiled for dev 【发布时间】:2019-02-01 06:37:42 【问题描述】:我正在使用 TypeScript 创建我的 nodejs 应用程序,该应用程序运行良好,因为 index.ts
正在成功编译和执行,但子文件夹中的 TypeScript 文件被忽略并且不构成开发监视的一部分。
有人可以帮忙吗?我使用yarn start
在开发模式下运行我的应用程序。我来自package.json
的脚本如下所示:
"scripts":
"start": "yarn run build:live",
"build": "rm -rf dist && tsc",
"build:live": "nodemon --exec ./node_modules/.bin/ts-node -- ./src/index.ts"
而我的tsconfig.json
看起来像这样:
"compilerOptions":
"outDir": "dist",
"target": "es2017",
"module": "commonjs",
"sourceMap": true,
"noUnusedLocals": true,
"typeRoots": [
"node_modules/@types"
]
,
"include": [
"src/**/**.ts",
"test/**/**.ts"
],
"exclude": [
"node_modules"
]
我曾尝试使用"build:live": "nodemon --exec ./node_modules/.bin/ts-node --project tsconfig.json"
作为我的开发脚本,但这会导致编译器挂起。
【问题讨论】:
【参考方案1】:ts-node
只会执行你的主文件src/index.ts
需要或导入的文件。您可以使用--files
选项使其在编译中包含tsconfig.json
中指定的所有文件,但这仅有助于声明事物,而不是在运行时定义它们。见the documentation。如果您需要在不使用 require 或 import 的情况下执行所有文件,请考虑使用其他工具运行您的项目。
【讨论】:
以上是关于未为 dev 编译子文件夹的主要内容,如果未能解决你的问题,请参考以下文章
未为自定义protractor.conf文件创建Webdriver实例
在 IntelliJ Idea 中未为 Kotlin @ConfigurationProperties 类生成 spring-configuration-metadata.json 文件