Tuesday, 28 March 2023

angular tsconfig.js specifies the root folder for absolute path, avoid using relative path in images etc as they might change in production

1) for images path use abosulte path 

llike assets/images/image1

do not use ../../images they cause problem in prod if folder changes

also check tsconfig.json for abosulte path startin gfolder in complierOptions: baseUrl

note: angular.json only specifies project working dir

 https://www.typescriptlang.org/tsconfig#baseUrl


#Base Url -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. E.g.

baseUrl ├── ex.ts ├── hello │ └── world.ts └── tsconfig.json

With "baseUrl": "./" inside this project TypeScript will look for files starting at the same folder as the tsconfig.json.

import { helloWorld } from "hello/world";
console.log(helloWorld);

If you get tired of imports always looking like "../" or "./", or needing to change them as you move files, this is a great way to fix that.

No comments:

Post a Comment