I'm trying to figure out correct approach for a javascript monorepo. Imagine monorepo containing packages / libraries:
root
- node_modules
- packages
+ lib-a
* node_modules
+ lib-b
* node_modules
Now let's say both lib-a
and lib-b
packages use webpack
as their build tool.
I see two approaches
Add
wepback
as dependency to root. Include "build" script in both packages:"build": "webpack -p --config webpack.config.js
.webpack.config.js
could include rootwebpack.config.js
. Then I could use tool likelerna
to run the build from root directory (which meanswebpack
binary is recognized. However I will be unable to run the build in specific packages sincewebpack
is not available there. I could probably change the build script to something like"build": "../../node_modules/.bin/webpack -p --config webpack.config.js
Always include
webpack
in each package. This means thatbuild
script will succeed. This also means that each package will have the same dependency and I should probably watch that each package uses samewebpack
version.
Basically what I'm getting at is how should packages inside monorepo be structured? If any package is published, should it always be possible to build
that package separately.