我会让我的Angular 2问题非常精确。
<强>1。我正在使用:
Angular 2, angular-cli: 1.0.0-beta.15, ( webpack building ) 节点:6.4.0, 操作系统:linux x64
<强>2。我想要实现的目标:
我想以这样一种方式构建我的项目,即在构建( ng build project-name ) 之后,我得到了我的 Angular 2 应用程序的静态文件,我可以直接从 chrome 运行它而无需使用 < strong>ng serve 或节点服务器。 我只想双击 index.html 并在本地运行该应用。
<强>3。同时,当我双击生成的 index.html 时,我在 chrome 浏览器控制台输出中得到的是:
file:///inline.js Failed to load resource: net::ERR_FILE_NOT_FOUND file:///styles.b52d2076048963e7cbfd.bundle.js Failed to load resource: net::ERR_FILE_NOT_FOUND file:///main.c45bb457f14bdc0f5b96.bundle.js Failed to load resource: net::ERR_FILE_NOT_FOUND file:///favicon.ico Failed to load resource: net::ERR_FILE_NOT_FOUND
据我了解,这与路径有关。构建和捆绑的应用程序无法找到正确的路径。所以我的问题是在哪里和如何我应该在我的应用程序或任何构建配置文件中更改路径让我的应用按照我在第 2 点
中描述的方式工作
预先感谢您就该主题提供直接而完整的回答,因为其他主题并未解释该主题的全部范围。
最佳答案
第一步:
运行命令
ng build
或
ng build -prod (then it will compact all files for production version)
第二步:
index.html 的变化
<base href="/"> to <base href="./">
第三步:
将所有文件放入服务器(可以是本地主机或任何服务器中的htdocs)
希望它能奏效。
关于javascript - 在没有节点服务器的情况下使用 angular-cli 在 Chrome 上运行本地构建的 angular 2 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39771458/