The entry point tells webpack where to start and follows the graph of dependencies to know what to bundle. You can think of your application's entry point as the contextual root or the first file to kick off your app.
In webpack we define entry points using the entry
property in our webpack configuration object.
Once you've bundled all of your assets together, you still need to tell webpack where to bundle your application. The webpack output
property tells webpack how to treat bundled code.
The minimum requirements for the output
property in your webpack config is to set its value to an object including the following two things:
- A
filename
to use for the output file(s).
- An absolute
path
to your preferred output directory.
webpack treats every file (.css, .html, .scss, .jpg, etc.) as a module. However, webpack itself only understands JavaScript.
Loaders in webpack transform these files into modules as they are added to your dependency graph.
At a high level, loaders have two purposes in your webpack config. They work to:
- Identify which file or files should be transformed by a certain Loader.
- Transform those files so that they can be added to your dependency graph (and eventually your bundle).
There are three ways to use loaders in your application:
- Configuration (recommended): Specify them under
module.rules
in your webpack.config.js file.
- Inline: Specify them explicitly in each
import
statement.
- CLI: Specify them within a shell command.
While Loaders only execute transforms on a per-file basis, plugins are most commonly used to perform actions and custom functionality on "compilations" or "chunks" of your bundled modules.
In order to use a plugin, you just need to require()
it and add it to the plugins
array. Since you can use a plugin multiple times in a config for different purposes, you need to create an instance of it by calling it with new
.
Back to File
Back to Top