-
-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Closed
Description
This proposal is to support a simple and generic way to share code between create-react-app apps.
It can support monorepos and arbitrary source directory layout (e.g. for cleaning up relative import paths).
Example:
monorepo
|--cra-app1
|--package.json: srcPaths: [“../shared”]
|--src
|--file1.js: import comp1 from ‘comp1’ ← ok, shared/comp1
|--file2.js: import comp1 from ‘../../shared/comp1’ ← naughty, fails
|--cra-app2
|--package.json: srcPaths: [“../shared”, "./packages"]
|--src
|--file1.js: import comp1 from ‘comp1’ ← ok, shared/comp1
|--file2.js: import comp3 from ‘comp3’ ← ok, packages/comp3
|--packages
|--comp3
|--shared
|--comp1
|--comp2
Proposal:
- srcPaths are specified in package.json.
- Modules found in srcPaths are treated essentially the same as /src modules.
** transpiled using same cra config
** do not have their own package.json, do not specify own dependencies, .babelrc, etc.
** all tests in modules are included when running app tests - Modules in a srcPath are imported between /src or another srcPath using absolute import paths.
- Keep us sane?...don't allow overlapping srcPaths
The implementation to support this has a smallish footprint:
More info on this proposal including a working monorepo is here:
https://github.com/bradfordlemley/cra-share
I think the best part of this proposal is that it puts a lot of flexibility and power within the grasp of a novice developer. I think it works approximately how a novice developer would expect shared source to work. ...but...what are the issues with this proposal that I'm not seeing?
CrisLi and szarechaudeco and szare
Metadata
Metadata
Assignees
Labels
No labels