typescriptwebpack

Is it possible to write webpack config in typescript?


I saw, when searching, that there are typings for webpack. So it seems I can write webpack.config.js in typescript? But how can I do that?

enter image description here


Solution

  • You can use TS as your config file (webpack.config.ts)

    There is a clear clue for that, see Source Code

    The ** interpret** module used there is a list of extension files and their loaders.

    In the highlighted code webpack generates an array of all possible extension for the default files.

    For example, give webpack.config you will get an array with

    For this to work you need to install one of the packages that support loading your extension.

    For example, TS has some node packages that enable you to require('something.ts') and the package will do the work.

    The interpret package states that one of these packages is required

    ts-node, typescript-node, typescript-register, typescript-require

    So npm/yarn ts-node then just put a webpack.config.ts file and it will just work!

    EDIT: Webpack documentation now has dedicated section on configuration languages which includes TypeScript, CoffeeScript and Babel & JSX