You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/src/pages/guides/hosting-the-bundler.mdx
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,3 +55,67 @@ We use Service Workers to download all transpilers in the background, so the
55
55
next time a user visits your website they don't have to download the bundler
56
56
anymore and it can be used offline. This is possible because we host the service
57
57
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:
"/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