在ng build index.html在控制台中出现错误后,Angular 6

ZaI*_*hAn 6 console.log angular-cli angular ng-build angular-builder

我遇到问题,请帮助我解决此问题。问题是当我ng build在CLI中执行操作时,转到dist文件夹并运行index.html文件,以便控制台获取文件路径错误。

Failed to load resource: net::ERR_FILE_NOT_FOUND
polyfills.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
styles.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
scripts.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
vendor.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
main.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
/D:/favicon.ico:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
Run Code Online (Sandbox Code Playgroud)

Tus*_*ade 6

它仅与路径有关,在构建时只需使用--base-href标志-

ng build --prod --base-href ./
Run Code Online (Sandbox Code Playgroud)

现在,它在index.html中生成类似于以下内容的行-

<base href="./">
<!-- Note the file names here -->
<script type="text/javascript" src="runtime.30458714a8af1a2e7153.js"></script>
<script type="text/javascript" src="polyfills.db85ebdc34f3cf0f4d3f.js"></script>
<script type="text/javascript" src="scripts.e8fe6486441dc07e00c6.js"></script>
<script type="text/javascript" src="main.f9ea86a83ded92312d0f.js"></script>
Run Code Online (Sandbox Code Playgroud)

而已!它可以在任何地方工作,您只需要部署生产版本就可以了!

另外,请注意,如果您尝试从文件中直接运行index.html,它将无法正常运行。您需要将其放置在http服务器上(例如,本地的XAMPP