如何 运行 nodemon + ts-node + typescript 而无需全局安装 ts-node 或 npx?
How to run nodemon + ts-node + typescript altogether without having to install ts-node or npx globally?
我的 package.json
中有以下内容:
"scripts": {
"serve-fake-api": "nodemon fake-api/server.ts --watch 'fake-api/*.*'",
"serve-vue": "vue-cli-service serve",
"serve": "concurrently -k \"npm run serve-fake-api\" \"npm run serve-vue\"",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
我想重写 "serve-fake-api": "nodemon --exec 'ts-node' fake-api/server.ts --watch fake-api/*.*",
,但不必全局安装 ts-node
或 npx
。
我怎样才能做到这一点?
您可以只在本地安装 nodemon
和 ts-node
作为开发依赖项:
npm install -D ts-node nodemon
现在,当您 运行 npm 脚本时,他们将使用您的 local version by default:
In addition to the shell’s pre-existing PATH, npm run adds
node_modules/.bin to the PATH provided to scripts. Any binaries
provided by locally-installed dependencies can be used without the
node_modules/.bin prefix
我设法运行 了以下 packages.json
的所有内容:
{
"name": "rm-combo",
"version": "0.1.0",
"private": true,
"scripts": {
"serve-fake-api": "nodemon fake-api/index.ts --watch fake-api/*.*",
"serve-vue": "vue-cli-service serve",
"serve": "concurrently -k \"npm run serve-fake-api\" \"npm run serve-vue\"",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@types/node": "^12.12.7",
"axios": "~0.19.0",
"devextreme": "19.2.3",
"devextreme-vue": "19.2.3",
"element-ui": "~2.8.2",
"oidc-client": "~1.9.1",
"vue": "^2.6.10",
"vue-class-component": "^7.1.0",
"vue-property-decorator": "^8.3.0",
"vue-router": "^3.1.3",
"vuetify": "^2.1.10",
"vuex": "^3.1.2",
"vuex-class": "^0.3.2"
},
"devDependencies": {
"@types/express": "^4.17.2",
"@types/json-server": "^0.14.2",
"@vue/cli-plugin-typescript": "^4.0.5",
"@vue/cli-service": "^4.0.5",
"concurrently": "^5.0.0",
"devextreme-cldr-data": "^1.0.2",
"globalize": "^1.4.2",
"json-server": "^0.15.1",
"node-sass": "^4.13.0",
"nodemon": "^1.19.4",
"sass-loader": "^8.0.0",
"ts-node": "^8.5.0",
"typescript": "^3.7.2",
"vue-template-compiler": "^2.6.10"
}
和 ts 功能支持在那里做这个技巧:
我遇到过ts-node-dev
recently, which fuses together ts-node
and node-dev
。
无需配置。 CLI 参数是 ts-node
和 node-dev
接受的参数的组合,以及它自己的几个。
运行 像这样:
"start": "tsnd fake-api/server.ts"
我的 package.json
中有以下内容:
"scripts": {
"serve-fake-api": "nodemon fake-api/server.ts --watch 'fake-api/*.*'",
"serve-vue": "vue-cli-service serve",
"serve": "concurrently -k \"npm run serve-fake-api\" \"npm run serve-vue\"",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
我想重写 "serve-fake-api": "nodemon --exec 'ts-node' fake-api/server.ts --watch fake-api/*.*",
,但不必全局安装 ts-node
或 npx
。
我怎样才能做到这一点?
您可以只在本地安装 nodemon
和 ts-node
作为开发依赖项:
npm install -D ts-node nodemon
现在,当您 运行 npm 脚本时,他们将使用您的 local version by default:
In addition to the shell’s pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix
我设法运行 了以下 packages.json
的所有内容:
{
"name": "rm-combo",
"version": "0.1.0",
"private": true,
"scripts": {
"serve-fake-api": "nodemon fake-api/index.ts --watch fake-api/*.*",
"serve-vue": "vue-cli-service serve",
"serve": "concurrently -k \"npm run serve-fake-api\" \"npm run serve-vue\"",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@types/node": "^12.12.7",
"axios": "~0.19.0",
"devextreme": "19.2.3",
"devextreme-vue": "19.2.3",
"element-ui": "~2.8.2",
"oidc-client": "~1.9.1",
"vue": "^2.6.10",
"vue-class-component": "^7.1.0",
"vue-property-decorator": "^8.3.0",
"vue-router": "^3.1.3",
"vuetify": "^2.1.10",
"vuex": "^3.1.2",
"vuex-class": "^0.3.2"
},
"devDependencies": {
"@types/express": "^4.17.2",
"@types/json-server": "^0.14.2",
"@vue/cli-plugin-typescript": "^4.0.5",
"@vue/cli-service": "^4.0.5",
"concurrently": "^5.0.0",
"devextreme-cldr-data": "^1.0.2",
"globalize": "^1.4.2",
"json-server": "^0.15.1",
"node-sass": "^4.13.0",
"nodemon": "^1.19.4",
"sass-loader": "^8.0.0",
"ts-node": "^8.5.0",
"typescript": "^3.7.2",
"vue-template-compiler": "^2.6.10"
}
和 ts 功能支持在那里做这个技巧:
我遇到过ts-node-dev
recently, which fuses together ts-node
and node-dev
。
无需配置。 CLI 参数是 ts-node
和 node-dev
接受的参数的组合,以及它自己的几个。
运行 像这样:
"start": "tsnd fake-api/server.ts"