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/en/api/javascript-api/browser.mdx
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,38 @@ rspack({}, (err, stats) => {
29
29
});
30
30
```
31
31
32
+
## Response header settings
33
+
34
+
Note that `@rspack/browser` internally uses [SharedArrayBuffer](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) to implement shared memory across multiple threads. Therefore, you need to set response headers for both your development server and production deployment environment.
35
+
36
+
If you are using Rspack as your project's bundler, you can set it through [devServer.headers](/config/dev-server#devserverheaders):
37
+
38
+
```js title="rspack.config.mjs"
39
+
exportdefault {
40
+
devServer: {
41
+
headers: {
42
+
'Cross-Origin-Opener-Policy':'same-origin',
43
+
'Cross-Origin-Embedder-Policy':'require-corp',
44
+
},
45
+
},
46
+
};
47
+
```
48
+
49
+
If you are using Rsbuild as your project's bundler, you can set it through [server.headers](https://rsbuild.rs/config/server/headers#serverheaders):
50
+
51
+
```ts title="rsbuild.config.ts"
52
+
exportdefault {
53
+
server: {
54
+
headers: {
55
+
'Cross-Origin-Opener-Policy': 'same-origin',
56
+
'Cross-Origin-Embedder-Policy': 'require-corp',
57
+
},
58
+
},
59
+
};
60
+
```
61
+
62
+
For production environments, please refer to the documentation of your project's deployment platform.
63
+
32
64
## In-Memory File system
33
65
34
66
Since browsers cannot directly access the local file system, `@rspack/browser` provides an in-memory file system object `builtinMemFs` based on [memfs](https://www.npmjs.com/package/memfs) for reading and writing files in the browser environment. All file system reads and writes in both the Node.js and Rust sides are redirected to this in-memory file system, including reading project configuration, source code, `node_modules` dependencies, and writing output files.
@@ -158,3 +190,26 @@ If your project does not require dynamic loading and execution of JavaScript cod
158
190
159
191
If your project does not distribute untrusted code or distributing such code does not cause security issues, you can directly use `BrowserRequirePlugin.unsafeExecute`. For example, the [Rspack Playground](https://playground.rspack.rs/) does not involve user privacy or account security.
160
192
:::
193
+
194
+
## Known issues
195
+
196
+
-[napi-rs#2867](https://github.com/napi-rs/napi-rs/issues/2867): Currently, in projects using `@rspack/browser`, you need to inject `process.env.NODE_DEBUG_NATIVE`.
197
+
If you are using Rspack to bundle your project, you can set it with [DefinePlugin](/plugins/webpack/define-plugin):
0 commit comments