问题描述
我会让我的 Angular 2 问题非常精确.
I will make my Angular 2 question very precise.
1.我正在使用:
角 2,angular-cli: 1.0.0-beta.15, ( webpack building )节点:6.4.0,操作系统:linux x64
Angular 2, angular-cli: 1.0.0-beta.15, ( webpack building ) node: 6.4.0, os: linux x64
2.我想要达到的目标:
我想以这样的方式构建我的项目,在构建之后 ( ng build project-name ) 我得到我的 Angular 2 应用程序的静态文件,我可以直接从 chrome 运行它而不使用 ng serve 或节点服务器.我只想双击 index.html 并在本地运行应用程序.
I want to build my project in a way that after the build ( ng build project-name ) I get static files of my Angular 2 application, which I can run directly from chrome without using ng serve or the node server. I just want to double click index.html and run the app locally.
3.同时,当我双击生成的 index.html 时,我在 chrome 浏览器控制台输出中得到的是:
file:///inline.js 加载资源失败:net::ERR_FILE_NOT_FOUNDfile:///styles.b52d2076048963e7cbfd.bundle.js 无法加载资源:net::ERR_FILE_NOT_FOUNDfile:///main.c45bb457f14bdc0f5b96.bundle.js 无法加载资源:net::ERR_FILE_NOT_FOUNDfile:///favicon.ico 加载资源失败:net::ERR_FILE_NOT_FOUND
据我所知,这与路径有关.构建和捆绑的应用程序找不到正确的路径.所以我的问题是在哪里和如何我应该在我的应用程序或任何构建配置文件中更改路径为了让我的应用程序像我希望它以我在第 2 点
As I understand this is related to paths. The built and bundled application cannot find the right paths. So my question is where and how I should change the paths in my app or in any build configuration files in order for my app to work like I would like it to work in the way I have described in point number 2
预先感谢您对该主题的直接和完整的回答,因为其他主题并未解释该主题的完整范围.
Thank you in advance for a direct and full answer on that topic, because other topics are not explaining the full scope on that subject.
推荐答案
第一步:
运行命令
ng build
或
ng build -prod (then it will compact all files for production version)
第二步:
index.html 的变化
Change in index.html
<base href="/"> to <base href="./">
第三步:
将所有文件放入服务器(可以是本地主机或任何服务器中的htdocs)
Put all files into server(may be htdocs in localhost or any server)
希望它会奏效.
这篇关于在没有节点服务器的情况下使用 angular-cli 运行在 Chrome 本地构建的 angular 2 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!