如何 运行 .ts 文件脚本和 angular 5 使用 NPM 构建
How to run .ts file script and angular 5 build using NPM
我有一个扩展名为 .ts 的文件,我想先执行这个文件,然后到 运行 npm 运行 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 run compile
> 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\_logs18-03-01T14_47_01_179Z-debug.log
PS C:\Users\George35mk\Documents\Projects\gui\frontend\
如果我运行这是工作
ts-node git.version.ts
问题是我不能 运行 使用 npm 的串行脚本
Modify the package.json in the following way:
"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",
}
Explanation
&&
确保第一个命令运行,然后是另一个。
- 你不需要
npm-run-all
这样做
- 但是如果你想使用
npm-run-all
,那么做npm install npm-run-all --save-dev
我将 node/express/angular 与打字稿一起使用,发现只有一种方法可以使用一条命令完成所有工作而无需安装任何东西。
我的方式让我:
1.将node ts server文件编译成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"
我有一个扩展名为 .ts 的文件,我想先执行这个文件,然后到 运行 npm 运行 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 run compile
> 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\_logs18-03-01T14_47_01_179Z-debug.log
PS C:\Users\George35mk\Documents\Projects\gui\frontend\
如果我运行这是工作
ts-node git.version.ts
问题是我不能 运行 使用 npm 的串行脚本
Modify the package.json in the following way:
"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",
}
Explanation
&&
确保第一个命令运行,然后是另一个。- 你不需要
npm-run-all
这样做 - 但是如果你想使用
npm-run-all
,那么做npm install npm-run-all --save-dev
我将 node/express/angular 与打字稿一起使用,发现只有一种方法可以使用一条命令完成所有工作而无需安装任何东西。
我的方式让我: 1.将node ts server文件编译成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"