I have use Webpack for a long time and i always tangled with Webpack configurations. Recently, i try something to make VSCode show intellisense with Webpack and i found out webpack
is a function.
That's great because now i can enable intellisense without reading complicated boring documents. But when it runs, it's not wonderful as i respect. The type checking warning wrong. I tried to run webpack({})
in console and it return something like Compiler
schemas or default configuration. Although I found another way to enable intellisense using /** @type {webpack.Configuration} */
but still wonder; what does webpack()
function really do and do we need to care about it?
webpack
function enables a programmatic use of Webpack.
As Webpack Node.js API documentation states,
The imported webpack function is fed a webpack Configuration Object and runs the webpack compiler if a callback function is provided
<...>
If you don’t pass the webpack runner function a callback, it will return a webpack Compiler instance. This instance can be used to manually trigger the webpack runner or have it build and watch for changes, much like the CLI.
It isn't needed in webpack.config.js because this is already handled by Webpack CLI.