Next: , Previous: , Up: Webpack Concepts   [Index]


3.3.2.4 Loaders

Loaders allow webpack to process other types of files and convert them into valid modules that can be consumed by your application and added to the dependency graph.

At a high level, loaders have two properties in your webpack configuration:

  1. test’ property: identifies which file or files should be transformed.
  2. use’ property: indicates which loader should be used to do the transforming.
const path = require('path');

module.exports = {
  output: {
    filename: 'my-first-webpack.bundle.js'
  },
  module: {
    rules: [
      { test: /\.txt$/, use: 'raw-loader' }
    ]
  }
};

The configuration above has defined a ‘rules’ property for a single module with two required properties: ‘test’ and ‘use’. This tells webpack’s compiler the following: