Categories
TypeScript Answers

How to make web workers with TypeScript and Webpack?

Spread the love

Sometimes, we want to make web workers with TypeScript and Webpack.

In this article, we’ll look at how to make web workers with TypeScript and Webpack.

How to make web workers with TypeScript and Webpack?

To make web workers with TypeScript and Webpack, we add 'webworker' to compilerOptions.lib in tsconfig.json.

For instance, we write

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["webworker", "es5", "scripthost"]
  }
}

to add 'webworker' into compilerOptions.lib in tsconfig.json.

This will let the TypeScript compiler know that we can use web worker global variables in our project.

Conclusion

To make web workers with TypeScript and Webpack, we add 'webworker' to compilerOptions.lib in tsconfig.json.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *