With the resolver plugin below it is possible to have source relative imports in parcel (e.g. resolver.modules
from webpack).
This allows one to import their files without using relative imports. For example, given this configration in package.json:
{
...,
"resolver-src-root": {
"root": "/app",
"extensions": [".ts", ".tsx", ".js", ".jsx", ".json"]
}
}
and the following project structure:
package.json
/app
-- /components
---- /some
------ componentA.js
---- /another
------ componentB.js
-- api.js
The components can import eachother like this:
import ComponentA from "components/some/componentA"; // from componentB.js
import componentB from "components/another/componentB"; // from componentA.js
and the file api.js
can be imported by both like this:
import api from "api";