Loaders

Loaders allow you to pre-process and transform files as you load them. An example would be converting TypeScript to JavaScript. Let's see an example snippet from the webpack.config.js file:

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

The preceding code snippet tells webpack to process all the text files using a loader named raw-loader, and loads raw UTF-8 content from the file.

Loaders are essentially node modules that is a function like the following one, and the source parameter consists of all the source code as a string:

const loaderUtils = require('loader-utils');module.exports = function ...

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.