Nx recommends as best practices to have an app folder and a libs folder for reusable libraries, but in my opinion that structure is more recommendable if you are going to include also front-end projects or other type of not versioned and distributable applications. You could store your packages depending of their type in different folders, for example. I have to say pnpm is pretty neat I haven’t found a better alternative for dependency management on monorepos.The name of the folders is something that can be changed at your convenience. So I would recommend you going with it.Ī clean pnpm install (no cache at all) on netlify’s build servers for a project with 9 workspaces and ~250 direct dependencies takes about 50 seconds and re-linking those dependencies from cache on subsequent builds takes just 1 second. I’ve actually migrated my projects using pnpm workspaces out of netlify about a week ago, but the workaround I initially posted was still in use, and it worked perfectly: ~200 builds a month for almost a year without issues. I haven’t looked into it, but I guess it is now possible to add pnpm support via the new, beta API for build plugins. I tried such route myself in the past, before settling on this solution. To be fair, adding direct support for pnpm workspaces caching, specifically, in the way npm and yarn are supported, is a bit complicated. I’ve looked up and it seems there’s still no support for pnpm. Hey at the linked PR, it seems the author pulled out the pnpm bits from the PR but didn’t change the title/commit message.Īlso, proper support for pnpm should be added in the build image repo instead of the cli one. And unlike with yarn, we haven’t experienced issues with missing node_modules inside workspaces, since pnpm stores every dep inside the top-level node_modules (which is the only Netlify saves for cache) and pnpm install simply creates symlinks. We have been using this setup in prod without issues for a while now. Saving the store into node_modules makes the install quite fast. Even when I was able to make netlify save the pnpm cache, the install was not very efficient because pnpm had to resort to the copy strategy because netlify mounts the cache folder in a different drive, so symlinking is not possible. I initially tried to save it to the netlify cache dir, but netlify is picky on what saves in cache for the next build. The -store option tells pnpm where to save its “global” cache. Use the -r option only if you’re using workspaces. Assuming your build command is npm run build, you might add the following script into your top-level package.json: "prebuild": "] & npx install -r -store=node_modules/.pnpm-store || echo skiping pnpm install" This makes netlify skip their automatic npm install, to let pnpm take care of it.Īdd pnpm install as a build step in your build process, only for Netlify, most probably before anything else. If you’re using workspaces: add pnpm itself as a dev dependency on your top-level project, this so it is possible to use pnpm recursive commands inside your build scripts pnpm install -save-dev the NPM_FLAGS="-prefix=/" env var to your netlify.toml or set it on Netlify’s web dashboard Remove your package-lock.json or yarn.lock file and add it to your. Just as an informative note for future users, here some info on how to workaround Netlify’s CI in order to use pnpm instead of npm or yarn and pnpm workspaces.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |