liveBook · Manning

Loader

As explained in Essential TypeScript 5, Third Edition

A loader is a webpack extension that transforms a particular type of module content for inclusion in a bundle.

A loader is a webpack extension that transforms a particular type of module content so it can be included in the bundle. Webpack follows application dependencies and selects loaders from configured module rules. section 16.3

Configure loaders by matching files and assigning processing packages:

  • Use ts-loader for .ts files; it compiles TypeScript and feeds the resulting code into webpack's bundle. section 16.3
  • Use css-loader and style-loader together for CSS; the first handles CSS module content and the second incorporates the styles into the bundle. section 16.6.1

Adding Bootstrap CSS

Install Bootstrap with css-loader and style-loader, then add { test: /\.css$/, use: ["style-loader", "css-loader"] } to webpack.config.js. Import "bootstrap/dist/css/bootstrap.css" from src/index.ts; webpack can then include the stylesheet in bundle.js alongside the application code.

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Explains loader selection through webpack rules and practical configuration, stopping short of loader internals.
Examples
Uses ts-loader for TypeScript and css-loader with style-loader for Bootstrap CSS imported from index.ts.
What it assumes
Assumes familiarity with webpack configuration, module dependencies, npm packages, and TypeScript application files.
What you can do after
Operate/configure webpack loaders to compile TypeScript and bundle CSS into a self-contained application file.
How it connects
Connects loaders with webpack, bundlers, TypeScript, CSS, Bootstrap, and module dependencies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential TypeScript 5, Third Edition. The section links point to the parts of the book it draws on.