Is it possible to write webpack config in typescript?

前端 未结 5 1323
礼貌的吻别
礼貌的吻别 2020-12-25 09:40

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?

5条回答
  •  清酒与你
    2020-12-25 10:18

    If you do not want to transpile your webpack config and then pass it to webpack script in two steps I came up with other solution. Using webpack programmatically is really easy, so I have created a build script build.ts

    import webpack from 'webpack'
    
    import config from './webpack.config'
    
    webpack(config, (err, stats) => err 
        ? console.log(err) 
        : console.log(stats)
    );
    

    Then you may run npm script with ts-node like so

    "build": "ts-node --project ./path-to/tsconfig.json ./build.ts"
    

提交回复
热议问题