[英]Angular: setting baseHref does not create subfolders
When you run ng build
with --base-href "/some/path/"
, why does angular not create subdirectories according to the path? 当使用--base-href "/some/path/"
运行ng build
时,为什么angular不根据路径创建子目录? When I start a http-server in my /dist/ I get errors like GET /some/path/assets/images/image.png Not Found!
当我在/ dist /中启动http服务器时,出现诸如GET /some/path/assets/images/image.png Not Found!
错误GET /some/path/assets/images/image.png Not Found!
thrown in my face. 扔在我的脸上。 when you look into /dist/
, the problem is clear: there is only the assets folder directly, not inside other folders. 当您查看/dist/
,问题很明显:直接只有资产文件夹,而在其他文件夹中却没有。
So what is the right way to set a baseHref? 那么设置baseHref的正确方法是什么?
What I try to accomplish is having different versions of the app (with different i18n locales) being served from the same domain but with a different baseHref, eg /EN/
, /FR/
and so on. 我试图完成的工作是从同一域提供不同版本的应用程序(具有不同的i18n语言环境),但具有不同的baseHref,例如/EN/
, /FR/
等。
I had the same problem with my app that uses i18n. 我的应用程序使用i18n时遇到了同样的问题。 First of all: Angular is still beeing developed, so for example i18n doesnt work out of the box, depending on what you want to do here is a roadmap for i18n on GitHub #16477 maybe still in version 5 they want to implement dynamic translation so you won't need a different app for each language, but thats a different issue ;) 首先:Angular仍在开发中,因此例如i18n不能立即使用,这取决于您要执行的操作,这是GitHub #16477上i18n的路线图,也许它们仍在第5版中,他们想实现动态翻译,所以您不需要为每种语言使用不同的应用程序,但这就是一个不同的问题;)
I suppose youz are looking for: 我想你正在寻找:
--output-path
with this command you set the path where your actual files will be stored (from Angular wiki ) 使用此命令,您可以设置实际文件的存储路径(来自Angular wiki )
--base-href
only sets the href attribute in your index.html but since you want to set the path for the files you need to use --output-path
--base-href
仅在index.html中设置href属性,但是由于要设置文件的路径,因此需要使用--output-path
I'm not sure if you also need to set --deploy-url
for your apps, anyway --deploy-url /en
creates the following index.html
: 我不确定您是否还需要为应用程序设置--deploy-url
,无论如何--deploy-url /en
会创建以下index.html
:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
<base href="/">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" type="image/x-icon" href="assets/favicon_link_icon.png">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="/en/styles.xxx.bundle.css" rel="stylesheet"/>
</head>
<body>
<app-root></app-root>
<script type="text/javascript" src="/en/inline.xxx.bundle.js"></script>
<script type="text/javascript" src="/en/polyfills.xxx.bundle.js"></script>
<script type="text/javascript" src="/en/main.xxx.bundle.js"></script>
</body>
</html>
--output-path ./dist/en
creates a new folder dist/en
with almost the same index.html
only the src
path is missing the /en/
prefix --output-path ./dist/en
使用几乎相同的index.html
创建一个新文件夹dist/en
,仅src
路径缺少/en/
前缀
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.