Is there a way to set a urlBase
to avoid relative paths when developing a theme?
The idea is that for a tree structure like this oneβ¦
.
βββ CHANGELOG.md
βββ package.json
βββ src
βββ components
β βββ featured-media.js
β βββ header.js
β βββ index.js
β βββ link.js
β βββ list
β β βββ index.js
β β βββ list-item.js
β β βββ list.js
β β βββ pagination.js
β βββ loading.js
β βββ menu-icon.js
β βββ menu-modal.js
β βββ menu.js
β βββ nav.js
β βββ page-error.js
β βββ post.js
β βββ title.js
βββ helpers
β βββ DataState.js
βββ index.js
You can import from anywhere the component Title
just by doing
import Title from 'components/title'
instead of doing
import Title from '../title'
import Title from './title'
import Title from '../../title'
import Title from '../../../../title'
With create-react-app
used to be done by setting and environment variable w/ value
NODE_PATH=src/
With the latest version of create-react-app
you have to create a jsconfig.json
with thisβ¦
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
Related info: