抱歉,如果某个地方回答了这个问题。
我可以将Angular应用程序部署到heroku,但是尽管采取了本文中的步骤,但它不会在PRODUCTION模式下运行。
https://medium.com/@hellotunmbi/how-to-deploy-angular-application-to-heroku-1d56e09c5147
我们的环境文件夹中有两个文件:
从本质上讲,似乎Heroku使用了名为environment.ts的第二个环境文件,而不是使用environment.prod.ts
在environment.ts中,有一个env变量:
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false,
};
Run Code Online (Sandbox Code Playgroud)
fileReplacements也正确设置。
environment.prod.ts文件还包含变量production,其值为true。
使用以下简单代码,我们知道它不是生产模式:
export class SettingsComponent implements OnInit {
environmentIsProduction: boolean = false;
constructor() {
}
ngOnInit() {
this.environmentIsProduction = environment.production;
console.warn('Environment is PRODUCTION: ' + environment.production);
}
}
Run Code Online (Sandbox Code Playgroud)
有谁能对我们可能已经忘记的步骤提出建议?
这是整个package.json文件
{
"name": "angular-frontend",
"version": "0.0.0",
"engines": {
"node": "8.11.2",
"npm": "6.2.0"
},
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot --prod"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cdk": "^7.2.1",
"@angular/cli": "~6.2.3",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/compiler-cli": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"@ng-bootstrap/ng-bootstrap": "^3.2.2",
"@swimlane/ngx-datatable": "^14.0.0",
"angular-notifier": "^4.1.1",
"angular-svg-icon": "^7.0.1",
"angularx-social-login": "^1.2.6",
"bootstrap": "^4.1.3",
"core-js": "^2.5.4",
"express": "^4.16.4",
"flag-icon-css": "^3.3.0",
"jquery": "^1.9.1",
"jw-bootstrap-switch-ng2": "^2.0.2",
"ng-connection-service": "^1.0.4",
"ng-pick-datetime": "^6.0.16",
"ng2-currency-mask": "^5.3.1",
"ng2-nouislider": "^1.7.12",
"ngx-bootstrap": "^3.0.1",
"ngx-flag-icon-css": "^1.0.1",
"ngx-webstorage-service": "^3.1.1",
"nouislider": "^11.0.0",
"path": "^0.12.7",
"popper.js": "^1.14.4",
"rellax": "^1.7.0",
"rxjs": "~6.2.0",
"typescript": "~2.9.2",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.8.0",
"@angular/cli": "~6.2.3",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这可以对某人有所帮助。
终于找到了解决方案:https : //devcenter.heroku.com/articles/nodejs-support#heroku-specific-build-steps
在package.json中,有必要更改以下行:
"postinstall": "ng build --aot --prod"
Run Code Online (Sandbox Code Playgroud)
至
"heroku-postbuild": "ng build --configuration=production"
Run Code Online (Sandbox Code Playgroud)
尽管原始命令确实执行了生产构建和文件名混淆等所有步骤,但修剪了……之后,它又运行了正常的ng构建。
我在部署到Heroku期间的日志中注意到了此行为。
一旦使用了heroku-postbuild,该构建只发生了一次……用于生产。
| 归档时间: |
|
| 查看次数: |
650 次 |
| 最近记录: |