I am currently working on two applications, glowystuff-web and glowy-ui. Glow-UI is a shared UI library that I intend to use in future projects as my own version of React Bootstrap.
However, I am facing a challenge with defining glowy-ui as a dependency in packages/glowystuff-web/package.json:
{
"dependencies": {
"glowy-ui": "*"
},
"scripts": {
"build": "gatsby build"
}
}
Every time I try to build without running yarn build first, I encounter errors like the following:
3:47:15 PM: failed Building production JavaScript and CSS bundles - 24.131s
3:47:15 PM: error Generating JavaScript bundles failed
3:47:15 PM: Can't resolve 'glowy-ui' in '/opt/build/repo/packages/glowystuff-web/src/components'
3:47:15 PM: If you're trying to use a package make sure that 'glowy-ui' is installed. If you're trying to use a local file make sure that the path is correct.
I have consulted various resources for setting up Monorepos with Yarn Workspaces on Netlify but I am still unclear on how to ensure that building occurs when necessary. Adding the following script to packages/glowystuff-web/package.json seems excessive:
"scripts": {
"build": "yarn workspace glowy-ui build && gatsby build"
}
It appears that this script would trigger a build of the UI library every time the main web app (glowystuff-web) is built, even if there are no changes to the UI library code.
While creating a private NPM package for glowy-ui is a viable solution, my preference is to keep everything within a single GitHub repository using Yarn Workspaces. Why publish when all files are readily accessible?
Therefore, I am seeking advice on the best approach to facilitate builds on Netlify/Yarn Workspaces while also optimizing caching where applicable.
Additional information on current builds - netlify.tomls:
We have adopted the code-as-config methodology for Netlify builds. The current setup in packages/glowystuff-web/netlify.toml is as follows:
[build]
publish = "public/"
command = "yarn build"
Furthermore, glowy-ui serves as both the UI library and the accompanying Storybook application. Below is the configuration in packages/glowy-ui/netlify.toml:
[build]
publish = "storybook-static"
command = "yarn build-storybook"