1

我有一个扩展名为 .ts 的文件,我想先执行这个文件,然后运行 ​​npm run build 来构建我的 angular 5 项目

package.json
 "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "compile": "npm-run-all myts build",
    "myts": "ts-node git.version.ts",
    "build": "ng build --prod",
    "test": "ng test",
  },

我得到这个错误

npm 运行编译

> ng-forms-api@0.0.0 compile C:\Users\George35mk\Documents\Projects\gui\frontend\> 
npm-run-all myts build

'npm-run-all' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ng-forms-api@0.0.0 compile: `npm-run-all myts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ng-forms-api@0.0.0 compile script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\George35mk\AppData\Roaming\npm-cache\_logs\2018-03-01T14_47_01_179Z-debug.log
PS C:\Users\George35mk\Documents\Projects\gui\frontend\

如果我运行这是工作

ts 节点 git.version.ts

问题是我无法使用 npm 运行串行脚本

4

2 回答 2

2

通过以下方式修改package.json:

"scripts": {
  "ng": "ng",
  "start": "ng serve",
  "compile": "npm run myts && npm run build",
  "myts": "ts-node git.version.ts",
  "build": "ng build --prod",
  "test": "ng test",
}

解释

  1. &&确保第一个命令运行,然后是另一个。
  2. 你不需npm-run-all要这样做
  3. 但是如果你想使用npm-run-all,那么做npm install npm-run-all --save-dev
于 2018-03-01T15:44:50.677 回答
2

我将 node/express/angular 与 typescript 一起使用,发现只有一种方法可以使用一个命令完成所有工作,而无需安装任何东西。

我的方式让我: 1. 将节点 ts 服务器文件编译为 js 并观察 ts 文件的变化 2. 编译 angular 项目,将其提供给节点服务器并观察 angular 的变化 3. 运行节点服务器并在有变化时重新启动它.

我所做的就是运行“npm start”

我的 package.json

{
  "name": "node",
  "version": "1.0.0",
  "description": "",
  "main": "./dist/server.js",
  "scripts": {
    "start": "start tsc --watch & cd ../angular & start ng build --watch & cd ../node & timeout 15 & start nodemon --watch ../angular/dist --watch dist"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.3",
    "ws": "^6.0.0"
  },
  "devDependencies": {
    "@types/express": "^4.16.0",
    "@types/node": "^10.9.2",
    "@types/ws": "^6.0.0",
    "typescript": "^3.0.1"
  }
}

我的项目结构:

My_project
 - node
 - angular

tsconfig.json optons:
    "outDir": "dist", 
    "rootDir": "src"
于 2018-08-27T19:12:21.823 回答