1, Loader
In the previous section we talked about some of the basic concepts of webpack, and then we continue to explore the Webpack Loader, then what is Loader? What is the role of it?
- Webpack itself can only handle JavaScript modules , and if you want to work with other types of files, you need to convert using loader.
- Loader can be understood as a converter for modules and resources, which itself is a function that accepts the source file as a parameter and returns the result of the transformation. This allows us
require to load any type of module or file, such as Coffeescript, JSX, less, or pictures.
Characteristics of 1.1 Loader
- Loader can be chained by pipeline, each Loader can convert the resource into any format and pass it to the next Loader, but the last Loader must return JavaScript.
- Loader can be executed synchronously or asynchronously.
- Loader is running in the node. JS environment, so you can do whatever it is possible.
- Loader can accept parameters to pass configuration items to Loader.
- Loader can be bound to different types of files through file extensions (or regular expressions).
- Loader can be
npm published and installed.
- In addition to
package.json the main designations passed, the usual modules can also be exported with a loader to use.
- Loader can access the configuration.
- Plugins allow loader to have more features.
- Loader can issue additional arbitrary files.
The 1.2 Loader itself is also a JavaScript module running in the node. JS environment, which typically returns a function.
Loader can be require() added when referencing a module, can be bound in the Webpack global configuration, and can also be used on a command line basis.
Webpack Basic Tutorial: (ii)