Skip to content

Commit 7d3e23c

Browse files
authored
Merge pull request #110 from nulladdict/docs-options
docs: document missing options
2 parents 111e17a + e755a1f commit 7d3e23c

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ instance.expensive(1000).then( count => {
4646

4747
### Options
4848

49+
Workerize options can either be defined in your Webpack configuration, or using Webpack's [syntax for inline loader options](https://webpack.js.org/concepts/loaders/#inline).
50+
4951
#### `inline`
5052

5153
Type: `Boolean`
@@ -60,11 +62,94 @@ You can also inline the worker as a BLOB with the `inline` parameter
6062
options: { inline: true }
6163
}
6264
```
63-
or
65+
66+
or
67+
6468
```js
6569
import worker from 'workerize-loader?inline!./worker'
6670
```
6771

72+
#### `name`
73+
74+
Type: `String`
75+
Default: `[hash]`
76+
77+
Customize filename generation for worker bundles. Note that a `.worker` suffix will be injected automatically (`{name}.worker.js`).
78+
79+
```js
80+
// webpack.config.js
81+
{
82+
loader: 'workerize-loader',
83+
options: { name: '[name].[contenthash:8]' }
84+
}
85+
```
86+
87+
or
88+
89+
```js
90+
import worker from 'workerize-loader?name=[name].[contenthash:8]!./worker'
91+
```
92+
93+
#### `publicPath`
94+
95+
Type: `String`
96+
Default: based on `output.publicPath`
97+
98+
Workerize uses the configured value of `output.publicPath` from Webpack unless specified here. The value of `publicPath` gets prepended to bundle filenames to get their full URL. It can be a path, or a full URL with host.
99+
100+
```js
101+
// webpack.config.js
102+
{
103+
loader: 'workerize-loader',
104+
options: { publicPath: '/static/' }
105+
}
106+
```
107+
108+
#### `ready`
109+
110+
Type: `Boolean`
111+
Default: `false`
112+
113+
If `true`, the imported "workerized" module will include a `ready` property, which is a Promise that resolves once the Worker has been loaded. Note: this is unnecessary in most cases, since worker methods can be called prior to the worker being loaded.
114+
115+
```js
116+
// webpack.config.js
117+
{
118+
loader: 'workerize-loader',
119+
options: { ready: true }
120+
}
121+
```
122+
123+
or
124+
125+
```js
126+
import worker from 'workerize-loader?ready!./worker'
127+
128+
let instance = worker() // `new` is optional
129+
await instance.ready
130+
```
131+
132+
#### `import`
133+
134+
Type: `Boolean`
135+
Default: `false`
136+
137+
When enabled, generated output will create your Workers using a Data URL that loads your code via `importScripts` (eg: `new Worker('data:,importScripts("url")')`). This workaround enables cross-origin script preloading, but Workers are created on an "opaque origin" and cannot access resources on the origin of their host page without CORS enabled. Only enable it if you understand this and specifically need the workaround.
138+
139+
```js
140+
// webpack.config.js
141+
{
142+
loader: 'workerize-loader',
143+
options: { import: true }
144+
}
145+
```
146+
147+
or
148+
149+
```js
150+
import worker from 'workerize-loader?import!./worker'
151+
```
152+
68153
### About [Babel](https://babeljs.io/)
69154

70155
If you're using [Babel](https://babeljs.io/) in your build, make sure you disabled commonJS transform. Otherwize, workerize-loader won't be able to retrieve the list of exported function from your worker script :

0 commit comments

Comments
 (0)