Even though webpack is used most commonly for bundling web applications, it can do more. You can use it to target Node or desktop environments, such as Electron. Webpack can also bundle as a library while writing an appropriate output wrapper making it possible to consume the library.
Webpack's output target is controlled by the
target field. You'll learn about the main targets next and dig into library specific options after that.
Webpack uses the web target by default. This is ideal for a web application like the one you have developed in this book. Webpack bootstraps the application and load its modules. The initial list of modules to load is maintained in a manifest, and then the modules can load each other as defined.
The webworker target wraps your application as a web worker. Using web workers is valuable if you want to execute computation outside of the main thread of the application without slowing down the user interface. There are a couple of limitations you should be aware of:
Web workers and their usage are discussed in detail in the Web Workers chapter.
Webpack provides two Node-specific targets:
async-node. It uses standard Node
require to load chunks unless async mode is used. In that case, it wraps modules so that they are loaded asynchronously through Node
node-webkit- Targets NW.js while considered experimental.
electron-main- Targets Electron main process.
electron-renderer- Targets Electron renderer process.
Webpack supports targets beyond the web. Based on this you can say name "webpack" is an understatement considering its capabilities.
targetfield. It defaults to
web, but accepts other options too.
You'll learn how to bundle libraries in the next chapter.
This book is available through Leanpub (digital), Amazon (paperback), and Kindle (digital). By purchasing the book you support the development of further content. A part of profit (~30%) goes to Tobias Koppers, the author of webpack.