在我使用Typescript编写的NodeJS项目中,我引用了几个.pem
文件来启动https
服务器。
问题是编译完代码后,.pem
文件不会出现在输出目录中。
如何让它们以与.ts
形式相同的方式显示在文件结构中。
以下是我的server.ts
代码(摘要):
..
let server: Server;
try {
const options = {
key: fs.readFileSync("./https/key.pem"),
cert: fs.readFileSync("./https/cert.pem")
};
server = https.createServer(options, app);
}
..
供参考,这是我的package.json
{
"name": "manicmusic-app",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"start": "ng serve",
"build": "ng build",
"_server:run": "ntsc -p ./server && concurrently \"ntsc -w -p ./server\" \"nodemon --delay 10 dist/server_parent/server/bin/www.js\"",
},
"private": true,
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5",
"@types/body-parser": "^1.16.7",
"@types/jsonwebtoken": "^7.2.3",
"@types/mongoose": "^4.7.27",
"angular2-jwt": "^0.2.3",
"body-parser": "^1.18.2",
"bootstrap": "^4.0.0-beta.2",
"connect-mongo": "^2.0.0",
"core-js": "^2.4.1",
"easy-pbkdf2": "^0.1.2",
"express": "^4.16.2",
"express-session": "^1.15.6",
"jsonwebtoken": "^8.1.0",
"mongoose": "^4.13.4",
"octicons": "^7.0.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.3.2",
"@angular/compiler-cli": "^4.2.4",
"@angular/language-service": "^4.2.4",
"@types/connect-mongo": "0.0.34",
"@types/express": "^4.0.39",
"@types/googlemaps": "^3.29.2",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^8.0.53",
"codelyzer": "~3.1.1",
"concurrently": "^3.5.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"nodemon": "^1.12.1",
"ntypescript": "^1.201706190042.1",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
}
答案 0 :(得分:0)
有两种方法可以解决您的问题:
您需要示例吗?
答案 1 :(得分:0)
yarn add cpx
或npm i cpx
'scripts: {
"build": "tsc -p . && yarn run cp",
"cp": "cpx ./src/ab.pem build/"
}
cpx yourfile yourDestination
yarn build
时,它将自动对文件进行cp 加油!