用angular7创建一个简单的项目。其在开发模式下运行良好。
完成后,通过ng build --prod命令进行构建。
它生成带有资产和一些的index.html的index.htmldist文件夹
检查索引文件

如果在浏览器中打开,它只是白色的屏幕。
我错过的任何解决方案。
package.json
{
"name": "app2",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"@ng-bootstrap/ng-bootstrap": "^4.0.2",
"bootstrap": "^4.2.1",
"core-js": "^2.5.4",
"jquery": "^3.3.1",
"ngx-swiper-wrapper": "^7.2.1",
"popper": "^1.0.1",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.11.0",
"@angular/cli": "~7.1.2",
"@angular/compiler-cli": "~7.1.0",
"@angular/language-service": "~7.1.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"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": "~3.1.6"
}
}发布于 2019-02-06 12:14:02
我假设这是因为浏览器试图访问本地文件,这会向您的控制台抛出一个错误。由于文件访问受到限制,所以不能通过打开index.html直接提供服务。
但是,您可以使用lite-server创建静态服务器,也可以使用某些chrome extension.。
[试试这个:https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb ]
另一种选择是修改浏览器目标快捷方式并添加--web-security-disabled --allow-file-access-from-files标志。
阅读更多:How to launch html using Chrome at "--allow-file-access-from-files" mode?
发布于 2019-02-06 12:15:48
您总是需要一个服务器来运行角项目。当您运行ng serve时,在内部创建一个名为localhost的服务器。
您可以使用任何本地服务器(如iis )来运行该项目。
编辑:
如果要与xampp一起使用,则需要更改dist文件夹中的index.html中的base href。
步骤:1复制在dist中生成的app2文件夹并将其粘贴到xampp/htdocs中
步骤:2-xampp/htdocs/app2/index.html将<base href="/">转换为
<base href="./">步骤:3打开浏览器并导航到http://localhost/app2
https://stackoverflow.com/questions/54553358
复制相似问题