Skip to content

Commit 88b048c

Browse files
author
Samuel Maisonneuve
committed
Add a side note about using workerize-loader with Babel
1 parent ba41fb9 commit 88b048c

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ npm install -D workerize-loader
2525
```js
2626
// block for `time` ms, then return the number of loops we could run in that time:
2727
export function expensive(time) {
28-
let start = Date.now(),
29-
count = 0
30-
while (Date.now() - start < time) count++
31-
return count
28+
let start = Date.now(),
29+
count = 0
30+
while (Date.now() - start < time) count++
31+
return count
3232
}
3333
```
3434

@@ -40,10 +40,29 @@ import worker from 'workerize-loader!./worker'
4040
let instance = worker() // `new` is optional
4141

4242
instance.expensive(1000).then( count => {
43-
console.log(`Ran ${count} loops`)
43+
console.log(`Ran ${count} loops`)
4444
})
4545
```
4646

47+
### About [Babel](https://babeljs.io/)
48+
49+
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 :
50+
```js
51+
{
52+
test: /\.js$/,
53+
loader: "babel-loader",
54+
options: {
55+
presets: [
56+
[
57+
"env",
58+
{
59+
modules: false,
60+
},
61+
],
62+
]
63+
}
64+
}
65+
```
4766

4867
### Credit
4968

0 commit comments

Comments
 (0)