I have the following monorepo structure (using yarn workspaces).
packages
common
src
index.js
module1.js
module2.js
package.json
user
src
index.js
moduleA.js
mobuleB.js
package.json
package.json
My root package.json
{
"private": true,
"workspaces": ["packages/*"]
}
package.json from common
{
"name": "@packages/common",
"version": "1.0.0",
"main": "src/index.js",
"license": "MIT"
}
package.json from user
{
"name": "@packages/user",
"version": "1.0.0",
"main": "src/index.js",
"license": "MIT",
"dependencies": {
"@packages/common": "1.0.0"
}
}
As expected, the user package needs to "use / import" from the common package.
Here is my question: if I want to import module1 or module2 from the common package. Is there a way to do it directly, like:
import { Foo } from "@packages/common/src/module1";
Is this an anti-pattern? Should I only import from @packages/common, which would imply importing from common/src/index.js (given the main property on package.json)?
I pretty much would like to have access to any src/sub-folder/sub-file from the common package. Should I import | re-export everything from the common/src/index.js file, or is there a way to get those other files directly?