【发布时间】:2021-03-04 07:17:00
【问题描述】:
我有两个应用程序,glowystuff-web 和 glowy-ui。 Glowy-UI 是一个共享的 UI 库,我计划在其他项目中使用它,类似于我自己的 React Bootstrap。
这是挑战。我在packages/glowystuff-web/package.json 中将glowy-ui 定义为依赖项,如下所示:
{
"dependencies": {
"glowy-ui": "*"
},
"scripts": {
"build": "gatsby build"
}
}
除非我运行 yarn build(它使用 tsc 编译到 glowy-ui/lib)并将 JS lib/ 文件提交到 git(哎呀!)我得到这样的错误:
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.
就上下文而言,这些是我在 Netlify 上找到的有关 Monorepos(带有 Yarn 工作区)的最佳说明:
https://community.netlify.com/t/difficulty-with-new-monorepo-deployment-options/4381/9
我不清楚的是如何让 Netlify 知道需要进行构建。如果我在packages/glowystuff-web/package.json 上这样做:
"scripts": {
"build": "yarn workspace glowy-ui build && gatsby build"
}
...那么它似乎会在每次构建主 Web 应用程序 glowystuff-web 时构建 UI 库,即使 UI 库代码没有更新。
glowy-ui 的私有、已发布 NPM 包在这里可能是一个可行的选择,但我的想法是使用 Yarn Workspaces 建立一个 GitHub 存储库,我不需要在其中发布。毕竟,如果所有文件都可供阅读,为什么还要发布呢?
那么,在 Netlify/Yarn Workspaces 上,什么是最好的方法来构建东西,同时在适当的时候利用缓存?
当前版本的附加上下文 - netlify.tomls:
我们正在使用code-as-config 方法来构建 Netlify。这是当前packages/glowystuff-web/netlify.toml:
[build]
publish = "public/"
command = "yarn build"
Glowy-UI 既是 UI 库,也是随附的故事书应用程序,所以这里是当前的packages/glowy-ui/netlify.toml:
[build]
publish = "storybook-static"
command = "yarn build-storybook"
【问题讨论】:
标签: typescript yarnpkg netlify lerna yarn-workspaces