角度:设置baseHref不会创建子文件夹 [英] Angular: setting baseHref does not create subfolders

查看:64
本文介绍了角度:设置baseHref不会创建子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

--base-href "/some/path/"运行ng build时,为什么angular不根据路径创建子目录?当我在/dist/中启动http服务器时,出现诸如GET /some/path/assets/images/image.png Not Found!之类的错误.当您查看/dist/时,问题很明显:直接只有资产文件夹,而没有其他文件夹内部.

When you run ng build with --base-href "/some/path/", why does angular not create subdirectories according to the path? When I start a http-server in my /dist/ I get errors like 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.

那么设置baseHref的正确方法是什么?

So what is the right way to set a baseHref?

我要完成的工作是从同一域提供不同版本的应用程序(具有不同的i18n区域设置),但具有不同的baseHref,例如/EN//FR/等.

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的应用程序也遇到了同样的问题.首先:Angular仍在开发中,因此例如i18n不能立即使用,这取决于您要在此处做什么,这是GitHub

I had the same problem with my app that uses 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 ;)

我想你正在寻找:

--output-path

使用此命令,您可以设置实际文件的存储路径(来自 Angular Wiki )
--base-href仅在index.html中设置href属性,但是由于要设置文件的路径,因此需要使用--output-path

with this command you set the path where your actual files will be stored (from 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

我不确定您是否还需要为应用设置--deploy-url,反正--deploy-url /en会创建以下index.html:

I'm not sure if you also need to set --deploy-url for your apps, anyway --deploy-url /en creates the following 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创建一个几乎与index.html相同的新文件夹dist/en,仅src路径缺少/en/前缀

--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

这篇关于角度:设置baseHref不会创建子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆