tiagob / create-full-stack

Set up a TypeScript full stack with one command.
https://create-full-stack.com
MIT License
97 stars 9 forks source link

Absolute import on each packages #151

Closed sondh0127 closed 3 years ago

sondh0127 commented 3 years ago

We want to use "absolute import" inside each package. Like

web/tsconfig.json

baseUrl": "./"

so we can

import {Theme} from 'src/theme' 
=> ('packages/web/src/theme')

from web packages

Is there any alternative approach? like change the root tsconfig.json

tiagob commented 3 years ago

To make changes relative to the package you'll have to modify the package tsconfig.jsons. So for your packages/web example:

Modify packages/web/tsconfig.json to

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

This will trigger eslint errors which you can remove by modifying estlintrc.js to

module.exports = {
  extends: "eslint-config-create-full-stack",
  rules: {
    "import/no-unresolved": "off",
  },
};

TS baseUrl docs: https://www.typescriptlang.org/docs/handbook/module-resolution.html#base-url