简体   繁体   中英

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

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

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

Try to set baseUrl property in your tsconfig.json file like this:

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

baseUrl lets you set a base directory to resolve non-absolute module names.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM