【发布时间】:2015-10-23 08:32:43
【问题描述】:
我不想使用 grunt 或 gulp 来编译 ts 文件。我只想在我的 package.json 中这样做:
"scripts": {
"build": "tsc main.ts dist/"
},
有可能吗?
【问题讨论】:
我不想使用 grunt 或 gulp 来编译 ts 文件。我只想在我的 package.json 中这样做:
"scripts": {
"build": "tsc main.ts dist/"
},
有可能吗?
【问题讨论】:
"build": "tsc main.ts dist/"
强烈建议您使用tsconfig.json,然后使用-p 编译器选项来构建您的代码。
看:Compilation-Context
这里是使用 tsc 和 NPM 脚本的设置
初始化
npm init
npm install typescript --save
然后在你的 package.json 添加一些脚本:
"scripts": {
"build": "tsc -p .",
"start": "npm run build -- -w"
},
npm run build
npm start
享受?
【讨论】:
yarn run tsc --init (如果你使用 npm,则将 yarn 替换为 npm)
./src 应该指向包含您的 tsconfig 的目录。非常感谢这个:)
如果要编译运行,可以使用ts-node module。
npm install --save-dev ts-node
npm install --save-dev typescript
然后运行:
"scripts": {
"start": "ts-node index.ts"
},
index.ts 已导入的所有其他 typescripts 文件(以及从 index.ts 依赖项中的导入)都将被编译和执行。
【讨论】: