Support absolute paths with packages/ folder
Created by: gaearon
We’ve been using Lerna in Create React App, and I really like its approach. I think we should support a similar workflow (even without Lerna itself) for the “absolute paths” feature.
I imagine it working like this:
- In addition to
src
, you can create a special top-level folder calledpackages
. - Inside
packages
, you can create folders likeapp
,stuff
,lol
, and they all “see” each other so you can import things fromapp/whatever.js
orlol/wow.js
. You can also import any packages fromsrc
(but not vice versa). The entry point is stillsrc/index.js
. - We won’t add any magic handling that breaks Node resolution mechanism. Instead, whenever you
npm start
,npm test
, ornpm run build
, we will run a utility that creates symlinks fromnode_modules
of the root project to every folder inpackages
. It reports a hard error if there is a conflict. This means the authors can add server rendering after ejecting without scratching their heads, and that all the tooling assuming Node resolution mechanism keeps working.
package.json
public/
src/
index.js # can import app/banana.js or harry-potter/wand.js
packages/
app/
banana.js # can import harry-potter/wand.js
harry-potter/
wand.js # can import app/banana.js
node_modules/
app -> packages/app
harry-potter -> packages/harry-potter
other-deps
Am I missing why this would be a bad idea?