Utilizing chaining

Take advantage of the fact that loaders can be chained together. Instead of writing a single loader that tackles many tasks, write multiple loaders. Isolating them not only keeps each loader simple but may also allow them to be used for something more varied.

When rendering a template file with data specified via loader options or query parameters, for example, it could be written as a single loader that compiles the template from source, executes it, and returns a module that exports a string containing the HTML code. However, in the following guidelines, a simple apply-loader exists that can be chained with other open source loaders:

  • jade-loader: This converts the template to a module that exports a function.
  • apply-loader: This executes the function with loader options and returns basic HTML code.
  • e idea HTML-loader: This accepts the HTML code and outputs a valid JavaScript module.
  • The fact that loaders can be chained also means they don't necessarily have to output JavaScript, as long as the next loader in the chain can handle its output.

Webpack is always modular, so let's look at the advice concerning that when working with chained loaders.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.141.44