如何在不全局安装ts-node或npx的情况下完全运行nodemon + ts-node +打字稿?

时间:2019-11-09 20:45:52

标签: node.js typescript nodemon ts-node

我的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-nodenpx

我该如何实现?

3 个答案:

答案 0 :(得分:1)

您可以将nodemonts-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-nodenode-dev

无需配置。 CLI参数是ts-nodenode-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