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: README.md
+14-21Lines changed: 14 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,36 +125,29 @@ pnpm install sqlocal
125
125
126
126
### Cross-Origin Isolation
127
127
128
-
In order to persist data to the origin private file system, this package relies on APIs that require cross-origin isolation, so the page you use this package on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.
128
+
In order to persist data to the origin private file system, this package relies on APIs that require [cross-origin isolation](https://developer.mozilla.org/en-US/docs/Web/API/Window/crossOriginIsolated), so the page you use this package on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.
129
129
130
130
```http
131
131
Cross-Origin-Embedder-Policy: require-corp
132
132
Cross-Origin-Opener-Policy: same-origin
133
133
```
134
134
135
-
If your development server uses Vite, you can do this by adding the following to your Vite configuration.
How this is configured will depend on what web server or hosting service your application uses. If your development server uses Vite, [see the configuration below](#vite-configuration).
151
136
152
137
### Vite Configuration
153
138
154
-
Vite currently has an issue that prevents it from loading web worker files correctly with the default configuration. If you use Vite, please add the below to your Vite configuration to fix this.
139
+
Vite needs some additional configuration to handle web worker files correctly. If you or your framework uses Vite as your build tool, you can use SQLocal's Vite plugin to set this up.
140
+
141
+
The plugin will also enable [cross-origin isolation](#cross-origin-isolation) (required for origin private file system persistence) for the Vite development server by default. Just don't forget to also configure your _production_ web server to use the same HTTP headers.
142
+
143
+
Import the plugin from `sqlocal/vite` and add it to your [Vite configuration](https://vitejs.dev/config/).
Copy file name to clipboardExpand all lines: docs/guide/setup.md
+75-18Lines changed: 75 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ pnpm install sqlocal
24
24
25
25
## Cross-Origin Isolation
26
26
27
-
In order to persist data to the origin private file system, this package relies on APIs that require cross-origin isolation, so the page you use this package on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.
27
+
In order to persist data to the origin private file system, this package relies on APIs that require [cross-origin isolation](https://developer.mozilla.org/en-US/docs/Web/API/Window/crossOriginIsolated), so the page you use this package on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.
28
28
29
29
```http
30
30
Cross-Origin-Embedder-Policy: require-corp
@@ -80,27 +80,84 @@ export const db = new SQLocal({
80
80
81
81
## Vite Configuration
82
82
83
-
Vite currently has an issue that prevents it from loading web worker files correctly with the default configuration. If you use Vite, please add the below to your [Vite configuration](https://vitejs.dev/config/) to fix this. Don't worry: it will have no impact on production performance.
83
+
Vite needs some additional configuration to handle web worker files correctly. If you or your framework uses Vite as your build tool, you can use SQLocal's Vite plugin to set this up.
84
84
85
-
```javascript
86
-
optimizeDeps: {
87
-
exclude: ['sqlocal'],
88
-
},
89
-
```
85
+
The plugin will also enable [cross-origin isolation](#cross-origin-isolation) (required for origin private file system persistence) for the Vite development server by default. Just don't forget to also configure your _production_ web server to use the same HTTP headers.
90
86
91
-
To enable cross-origin isolation (required for origin private file system persistence) for the Vite development server, you can add this to your Vite configuration. Just don't forget to also configure your _production_ web server to use the same HTTP headers.
87
+
Import the plugin from `sqlocal/vite` and add it to your [Vite configuration](https://vitejs.dev/config/).
Since Angular does not expose its Vite configuration, you will need to configure it differently than other Vite-based frameworks. You can reference the [SQLocal Shell codebase](https://github.com/DallasHoff/sqlocal-shell) as an example.
101
+
102
+
First, it's important to disable prebundling in the development server so that Vite compiles the web workers correctly. You can do this in your serve architect in `angular.json`. This is also where you can set the headers for cross-origin isolation in development.
103
+
104
+
```json{8-12}
105
+
"architect": {
106
+
"build": { ... },
107
+
"serve": {
108
+
"builder": "@angular/build:dev-server",
109
+
"configurations": {
110
+
"development": {
111
+
"buildTarget": "my-app:build:development",
112
+
"headers": {
113
+
"Cross-Origin-Embedder-Policy": "require-corp",
114
+
"Cross-Origin-Opener-Policy": "same-origin"
115
+
},
116
+
"prebundle": false
117
+
}
103
118
},
119
+
"defaultConfiguration": "development"
120
+
}
121
+
}
122
+
```
123
+
124
+
You will also need to serve `sqlite3.wasm` from the root of your site. You can configure this in your build architect in `angular.json`.
Finally, you will need to create your own web worker file and pass it to the `SQLocal` constructor, rather than use the built-in worker. Run `ng create web-worker sqlocal` to make a web worker file, add [this code](https://github.com/DallasHoff/sqlocal-shell/blob/main/src/sqlocal.worker.ts), and pass the worker to SQLocal's `processor` option.
0 commit comments