我的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
。
我该如何实现?
答案 0 :(得分:1)
您可以将nodemon
和ts-node
本地安装为dev依赖项:
npm install -D ts-node nodemon
现在,当您运行npm脚本时,它们将使用您的local version by default:
除了shell先前存在的PATH外,npm run还添加了 node_modules / .bin到提供给脚本的PATH。任何二进制 由本地安装的依赖项提供的功能无需使用 node_modules / .bin前缀
答案 1 :(得分:1)
我最近遇到ts-node-dev
,它们融合了ts-node
和node-dev
。
无需配置。 CLI参数是ts-node
和node-dev
接受的参数的组合,最重要的是两个参数。
像这样运行:
"start": "tsnd fake-api/server.ts"
答案 2 :(得分:0)
我设法使用下面的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功能支持在该位置进行操作:https://stackoverflow.com/a/59126595/4636721