简体   繁体   English

角度:设置baseHref不会创建子文件夹

[英]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.

相关问题 Angular Monorepo 与 Basehref 共享资产 - Angular Monorepo shared assets with Basehref Angular 在 webjar 中发布的应用程序:baseHref 问题 - Angular App released in a webjar: issue with baseHref 在 Angular 14 中为 ng 服务覆盖 baseHref - override baseHref for ng serve in Angular 14 angular baseHref 对索引没有影响。html 链接 - angular baseHref no impact on index.html links Angular:如何在使用SSR时为开发中的资产设置baseHref - Angular: How to set baseHref for assets in development when using SSR 将Angular应用程序部署到具有更改的baseHref丢失文件的服务器 - Deploying Angular app to server with changed baseHref missing files 更新到 Angular 11 时,BaseHref 在 scss 文件中不起作用 - BaseHref not working in scss files when updating to Angular 11 用吸气剂创建服务并设置角度2? - create service with getter and setting in angular 2? 如何使用baseHref正确构建带有i18n的Angular 6应用程序到“语言环境目录”? - How to correctly build an Angular 6 app with i18n into “locale directories” with baseHref? Angular 7 SyntaxError:预期的表达式,当 basehref 从 root 更改时,在生产中得到 &#39;&lt; - Angular 7 SyntaxError: expected expression, got '< in production when ever basehref change from root
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM