Get npm Packages in Unity
Unity is a game-development environment that is used to create 2D and 3D games and deploy them on multiple platforms. Unity uses npm packages to distribute various types of features and assets. You can use an npm registry in Space to store and share Unity packages. Creating such a registry and publishing packages is the same as for the ordinary npm registry.
To use an npm package in a Unity project
Log in to the npm registry:
npm login --registry https://npm.pkg.jetbrains.space/mycompany/p/projectkey/mynpmhttps://npm.pkg.jetbrains.space/mycompany/p/projectkey/mynpm
is the registry URLmycompany
is the name of your company in Space,mynpm
is the registry name.
If you are not sure about the URL, you can copy the URL of a particular npm registry on the Packages page.
When asked for credentials, specify your Space username and password. npm uses permanent tokens for authentication. Once you log in to the registry, Space will automatically create a permanent token specifically for accessing the npm registry. This token will be saved in your local
.npmrc
configuration file . You can manage the created token on the My Profile | Security | Personal Tokens page.Open the
Packages
directory in the Unity project root and then open themanifest.json
Add the registry and the package dependency to
manifest.json
. For example, we want to reference themy.unity.package:1.2.3
:{ "scopedRegistries": [ { "name": "space", "url": "https://npm.pkg.jetbrains.space/mycompany/p/projectkey/mynpm", "scopes": [ "my.unity" ] } ], "dependencies": { "my.unity.package": "1.2.3", // other dependencies go here } }If the npm registry is private (in registry settings, Access is set to Private), you should provide Unity the authentication token for repository access (see step 2). Open the Unity Package Manager configuration file:
Windows:
%USERPROFILE%/.upmconfig.toml
macOS and Linux:
~/.upmconfig.toml
If the file doesn't exist, create it.
Add the registry URL and the authentication token to
upmconfig.toml
. For example:[npmAuth."https://npm.pkg.jetbrains.space/mycompany/p/projectkey/mynpm/"] token = "eyJhbGciOiJSUzUxMiJ9..." email = "me@example.com" alwaysAuth = trueOpen the Unity project in the Unity Editor. Unity must download the package and show it in the Package Manager.