Using Needle projects inside of a monorepo

Hi there,

I’ve been experimenting with creating a needle project inside a monorepo so that I could have a utility package that has multiple utility functions that I would be able to use in multiple needle projects. Including the utility package inside of my needle project’s package.json seems to break the app. Is this approach possible, what kind of configuration steps do I need to make if it is possible?

Original Post on Discord

by user 725499871615909899

Yep, that’s possible - you can basically make custom regular npm packages that have a peer dependency on needle engine.
From inside Unity we’re providing NpmDefs as a convenient way to create and use those utility packages - many of our samples use them this way, including a „Shared“ npmdef that is used across multiple samples

Take a look at this page for how to create npmdefs Project Structure | Needle Engine Documentation

Hey, having a look at the docs, it’s not very clear how this works

by user 725499871615909899

I’ve done the Create/NPM Definition and not sure whatb to do next

by user 725499871615909899

You can for example checkout our samples where we have a bunch of scenarios where scripts are shared among multiple projects. You create a npmdef and then drag it into the ExportInfo dependencies array. Does that answer your question?
image.png
image.png

Regarding “breaks the app” - can you share details about what breaks? Which project or project template (if any) are you using?

So this is creating a package in unity, then adding it to the project from unity?

by user 725499871615909899

Yes, it’s basically managing these steps to create a local npm package for you but can also be done manually if needed.

So I’m getting this error when pcreating a package in unity and pointing it to my existing package in my monorepo

by user 725499871615909899

Did you add it to Unity’s package manifest by any chance? I haven’t seen this warning before.

“by creating a package in Unity” you mean creating a npmdef? And can you elaborate what you mean by “pointing it to my existing package in my monorepo” ? The existing package is a web project (npm package) or a Unity package :slightly_smiling_face:

Nope, I’ve create Assets/ExternalPackages/Utils with NPM Definition (link to external package)

by user 725499871615909899

and the external package is a typescript package in my monorepo

by user 725499871615909899

Which Unity version is this?

2022.3.11f1

by user 725499871615909899

does the entry file to this package need to be a bundled js file?

by user 725499871615909899

no it doesnt, it needs to have a package.json / be a npm package - is this what you want? e.g. does your monorepo has scripts that you want to include in your web project?

yes so I’ve created my Unity/Needle project in monorepo/apps and I would like to use monorepo/packages/utils inside that project

by user 725499871615909899

Typically we put nodejs projects in a hidden subfolder so Unity’s AssetDB doesn’t import it