Skip to content

Commit e96aa2e

Browse files
authored
docs: redirect old private package page (#905)
1 parent e306409 commit e96aa2e

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

website/docs/next.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ module.exports = withNextra({
4747
destination: "/advanced-usage",
4848
permanent: true,
4949
},
50+
{
51+
source: "/guides/private-packages",
52+
destination: "/getting-started/private-packages",
53+
permanent: true,
54+
},
5055
];
5156
},
5257
});

website/docs/src/pages/guides/hosting-the-bundler.mdx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,67 @@ We use Service Workers to download all transpilers in the background, so the
5555
next time a user visits your website they don't have to download the bundler
5656
anymore and it can be used offline. This is possible because we host the service
5757
worker externally.
58+
59+
## Self-host private packages
60+
61+
<br />
62+
63+
<big>
64+
The custom private NPM registry allows Sandpack instances to retrieve private
65+
NPM packages from your own registry. This option requires running a third
66+
service (Node.js server) and configuring your Sandpack provider to consume
67+
these dependencies from another registry, not the public ones.
68+
</big>
69+
70+
**You'll need:**
71+
72+
- Host a Node.js server, which will run registry proxy;
73+
- GitHub/NPM authentication token with read access;
74+
75+
### Self-host the proxy
76+
77+
We recommend hosting a service that allows you to proxy your private packages from a registry (GitHub/Npm/your own) to a new one, which would make the packages available through another URL.
78+
As Sandpack bundles everything in-browser, it needs to find a way to connect to the registry which provides the project dependencies.
79+
First, Sandpack will try to fetch all dependencies from public registries, for example, `react` or `redux`. Then you can let Sandpack know which dependencies (or scoped dependencies) should be fetched from a different registry. For example, your custom registry.
80+
81+
#### Our recommendation
82+
83+
Suppose you don't already have a public registry, we recommend using [Verdaccio](https://verdaccio.org/). An open-source project that creates a private registry and can proxy other registries, such as GitHub and Npm.
84+
You can find examples of how to use the [examples folder](https://github.com/codesandbox/sandpack/tree/main/examples) in the main repository.
85+
86+
### Sandpack configuration
87+
88+
Once the proxy is running and configured, you need to set some options in your Sandpack context:
89+
90+
```jsx
91+
<Sandpack
92+
customSetup={{
93+
dependencies: { "@codesandbox/test-package": "1.0.5" },
94+
npmRegistries: [
95+
{
96+
enabledScopes: ["@codesandbox"],
97+
limitToScopes: true,
98+
registryUrl: "PROXY_URL",
99+
},
100+
],
101+
}}
102+
files={{
103+
"/App.js": `import { Button } from "@codesandbox/test-package"
104+
export default function App() {
105+
return (
106+
<div>
107+
<Button>I'm a private Package</Button>
108+
</div>
109+
)
110+
}
111+
`,
112+
}}
113+
template="react"
114+
/>
115+
```
116+
117+
### Security
118+
119+
It's essential to keep the information and tokens of the npm registry private! By using this method, it's best to keep in mind that it could expose all private packages in your account. Be careful where and how this proxy will be used. Make sure to use authentication tokens with **read-only access**.
120+
121+
It's also possible to expose only specific packages. If the custom scopes are `@scope/package-name` instead of `@scope/*`, it will only expose that particular package. You can even do something like `@scope/design-system*` to expose all packages of the design system.

0 commit comments

Comments
 (0)