Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

[QUESTION] How to share local/private code between apps? #2

Closed
mariusa opened this issue May 17, 2020 · 1 comment
Closed

[QUESTION] How to share local/private code between apps? #2

mariusa opened this issue May 17, 2020 · 1 comment

Comments

@mariusa
Copy link

mariusa commented May 17, 2020

What / Why

We'd like to share a few specific Vue components or .js files between multiple projects, front-end and backend (nodejs). Backend is published to a PaaS (Heroku).

There are alternatives, none good:
https://www.smashingmagazine.com/2018/04/sharing-code-between-projects/
https://stackoverflow.com/questions/11278921/how-to-share-code-between-node-js-apps
(don't want to go through the hassle of publishing private modules)

Bit looks good, but it requires signup to another 3rd party service. We already use github & npm.

Could npm v7 workspaces handle this? How?

Would be great to

  • have these shared files in 1 place, and when changed all projects know about them
  • committing to github (used also for deploying to Heroku) would include a copy of the files, so the project can run on Heroku too or also when others check out and they don't have the shared set of folders/files

Thanks!

@isaacs
Copy link
Contributor

isaacs commented May 19, 2020

A post on Workspaces is planned, and you can certainly use Workspaces for this use case, I'd imagine, though it'd be a little bit outside the target use case. Might be a bit too situation-specific for this blog series?

If you're comfortable using a monorepo, you could define your apps and all their shared deps as workspaces, so you'd have something like:

my-big-ol-mono-repo
+-- shared-deps
|   +-- foo
|   +-- bar
|   +-- baz
+-- applications
    +-- acme-customer-site
    +-- intranet
    +-- wob-blag

Then in the root package.json, have this:

{
  "workspaces": [
    "applications/*",
    "shared-deps/*"
  ]
}

That would, of course, re-publish all of your applications any time you push an update to any of them, or to any shared deps, and you'd have to configure your PaaS to use a specific folder to run each application. But it would guarantee that things stay in sync. (And there'd be nothing stopping you from also publishing some or all of those shared deps as npm packages, of course.)

@isaacs isaacs closed this as completed May 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants