i'm using create-react-app
+ typescript, and i want to add absolute paths.
i'm trying to get to the point i can use absolute paths, like so:
instead of import x from '../../../components/shell/shell'
use import x from '@components/shell/shell'
;
here is tsconfig.json file:
{
"extends": "./paths.json",
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"baseUrl": "src",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
I'm using extended file for paths, because from some reason npm start
overrides the file.
so is paths.json file:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@": ["./src"],
"@components/*": ["components/*]"
}
}
}
i also have an .env file:
NODE_PATH=src
i installed react-app-rewire
so i can config the paths,
and my config-ovverrides.js file looks like this:
module.exports = {
paths: function(paths, env) {
// ...add your paths config
return paths;
}
};
im stuck with connecting all the dots, it doesn't work and i still cant see what i need to do in order to config the webpack path object;
how can i implement paths in cra, ts, and rewire?