简体   繁体   English

使用 npm 构建时,如何让“--base-href”不扩展为绝对路径?

[英]How do I get "--base-href" to not expand to an absolute path when building using npm?

I'm using Angular 14 and NPM 8. I have this command for building my artifact...我正在使用 Angular 14 和 NPM 8。我有这个命令来构建我的工件......

npm run build -- --source-map --base-href=/my-app/ --output-path=dist/my-app/

The problem is, when my dist/my-app/index.html file is generated it contains the full path to my local machine问题是,当我的 dist/my-app/index.html 文件生成时,它包含我本地机器的完整路径

<!DOCTYPE html><html lang="en"><head>
  <meta charset="utf-8">
  <title>MyApp</title>
  <base href="C:/Program Files/Git/my-app/">

How do I run my build command such that my base href is only what is included after my "base-href" flag?如何运行我的构建命令,使我的基本 href 仅包含在我的“base-href”标志之后?

Try to set baseUrl property in your tsconfig.json file like this:尝试在tsconfig.json文件中设置baseUrl属性,如下所示:

{
  "compilerOptions": {
    "baseUrl": "./",
    ...
  },
}

baseUrl lets you set a base directory to resolve non-absolute module names. baseUrl允许你设置一个基目录来解析非绝对模块名称。

You can define a root folder where you can do absolute file resolution.您可以定义一个根文件夹,您可以在其中进行绝对文件解析。

With "baseUrl": "./" inside the project TypeScript will look for files starting at the same folder as the tsconfig.json .在项目 TypeScript 中使用"baseUrl": "./"将查找从与tsconfig.json相同的文件夹开始的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 构建 Angular 项目时,我可以在代码中检索 --base-href 参数值吗? - Can I retrieve the --base-href parameter value in my code when building an Angular project? Angular 2 - 在使用HashLocationStrategy时是base-href冗余 - Angular 2 - is base-href redundant when using HashLocationStrategy Angular 部署使用 npm 使用 base-href 参数运行构建不会呈现页面 - Angular deployment using npm run build with the base-href params doesnt render the page 如何强制Angular cli从绝对位置而不是base-href提供bundle文件 - How to force Angular cli to serve the bundle files from an absolute location rather then base-href Angular 7路由错误base-href被添加到路径 - Angular 7 routing error base-href gets prepended to path Angular CLI ng 与 --base-href 一起使用 - 我不明白它的行为 - Angular CLI ng serve with --base-href - I do not understand its behavior 使用 git bash 时,使用 base-href 构建的 Angular-cli 也会返回程序文件夹 - Angular-cli build with base-href also return programs folder when using git bash Angular 的动态 base-href - Dynamic base-href for Angular 如何从angular的外部链接中删除base-href? - How to remove base-href from a external link in angular? ng build --prod --base-href - ng build --prod --base-href
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM