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
As you don't want to wait for a new release for this plugin when a new version of comlink is released, this plugin has comlink as a peer dependency so you can install the version of comlink that you need.
35
34
36
35
### Add it to vite.config.js
37
36
38
37
```ts
39
38
// vite.config.js
40
-
import { comlink } from'vite-plugin-comlink'
39
+
import { comlink } from"vite-plugin-comlink";
41
40
42
41
exportdefault {
43
-
plugins: [
44
-
comlink()
45
-
],
42
+
plugins: [comlink()],
46
43
worker: {
47
-
plugins: () => ([
48
-
comlink()
49
-
])
50
-
}
51
-
}
44
+
plugins: () => [comlink()],
45
+
},
46
+
};
52
47
```
53
48
54
49
### Plugin order
55
-
Put this plugin as one of the first plugins. Only other plugins that create `ComlinkWorker` or `ComlinkSharedWorker` or transform files based on the existence of `ComlinkWorker` or `ComlinkSharedWorker` should come before this plugin!
56
50
57
-
## Usage
51
+
Put this plugin as one of the first plugins. Only other plugins that create `ComlinkWorker` or `ComlinkSharedWorker` or transform files based on the existence of `ComlinkWorker` or `ComlinkSharedWorker` should come before this plugin!
52
+
53
+
## Usage
54
+
58
55
```ts
59
56
// worker.js
60
-
exportconst add = (a:number, b:number) =>a+b
57
+
exportconst add = (a:number, b:number) =>a+b;
61
58
62
59
// main.ts
63
60
64
61
// Create Worker
65
-
const instance =newComlinkWorker(newURL('./worker.js', import.meta.url), {/* normal Worker options*/})
const api =newComlinkWorker<typeofimport('./worker')>(newURL('./worker', import.meta.url), {/* normal Worker options*/})
127
+
const api =newComlinkWorker<typeofimport("./worker")>(
128
+
newURL("./worker", import.meta.url),
129
+
{
130
+
/* normal Worker options*/
131
+
}
132
+
);
112
133
const worker =api[endpointSymbol];
113
134
```
114
135
115
136
## Module Worker
137
+
116
138
Not all Browsers support module Workers (see https://caniuse.com/mdn-api_worker_worker_ecmascript_modules).
117
139
118
140
This results in some drawbacks for fastest and best support:
119
141
120
142
For fast development we use module Workers as bundling the complete worker on the fly is not performant.
121
143
122
-
In default settings we bundle the whole worker at build to a single file. Therefore all browsers that support Workers, work in production.
144
+
In default settings we bundle the whole worker at build to a single file. Therefore all browsers that support Workers, work in production.
123
145
124
146
This is the same behavior as vite and it is NOT CHANGEABLE!
125
147
@@ -131,17 +153,28 @@ If you want a worker to be a module worker in production, add `type: 'module'` t
131
153
2. In production all browsers are supported
132
154
133
155
## Breaking changes
156
+
134
157
### v2 to v3
135
-
* remove of customConfigs breaking FF support in development for some projects and removing the abbility for inline worker. This is a limitation of vite so if vite adds support of it this plugin will follow
136
-
* remove of typefile. For typescript support please write your own type file or switch to the new syntax.
137
-
* remove of ServiceWorker support. This was considered unstable an it was hacky so it got removed. If vite adds support for building ServiceWorker this will be added!
138
-
* you have to add comlink to `worker.plugins` array.
158
+
159
+
- remove of customConfigs breaking FF support in development for some projects and removing the abbility for inline worker. This is a limitation of vite so if vite adds support of it this plugin will follow
160
+
- remove of typefile. For typescript support please write your own type file or switch to the new syntax.
161
+
- remove of ServiceWorker support. This was considered unstable an it was hacky so it got removed. If vite adds support for building ServiceWorker this will be added!
162
+
- you have to add comlink to `worker.plugins` array.
163
+
139
164
### v3 to v4
140
-
* the import syntax will be removed you have to switch to the new syntax!
141
-
* Removal of Warnings of leagacy (v2) options
142
-
* ESM support
143
-
* Better Source Maps
165
+
166
+
- the import syntax will be removed you have to switch to the new syntax!
167
+
- Removal of Warnings of leagacy (v2) options
168
+
- ESM support
169
+
- Better Source Maps
170
+
171
+
### v4 to v5
172
+
173
+
- some undocumented internal options got removed.
174
+
- full rewrite of the core transformer to fix a lot of bugs
175
+
- should be breaking free but as this is a big rewrite there might be breaking changes
0 commit comments