string-loader

raw JSON →
0.0.1 verified Sat Apr 25 auth: no javascript abandoned

A webpack loader that transforms resource file contents into a JavaScript string. Version 0.0.1 is a very early release with minimal documentation and no explicit stability guarantees. It exports a single function that returns the file content with escaped characters wrapped in quotes. Not actively maintained; latest commit from 2015. Alternative: raw-loader provides similar functionality with broader adoption and updates.

error Module build failed: TypeError: loader must be a function or a string
cause Using an outdated webpack configuration syntax or missing rule for string-loader.
fix
Ensure webpack config uses 'use: "string-loader"' in a rule object, and string-loader is installed.
gotcha This package is unmaintained since 2015. It may not work with modern webpack versions (v4+).
fix Use raw-loader instead, which is maintained and works with webpack 4+.
gotcha No version specified in package.json initial release; only v0.0.1 exists.
fix Pin exact version and test thoroughly.
npm install string-loader
yarn add string-loader
pnpm add string-loader

Shows how to configure webpack to load .html files as strings using string-loader.

// webpack.config.js
module.exports = {
  entry: './src/index.js',
  output: { filename: 'bundle.js' },
  module: {
    rules: [
      {
        test: /\.html$/,
        use: 'string-loader'
      }
    ]
  }
};

// src/index.js
const template = require('./template.html');
console.log(template); // prints the HTML file content as a JavaScript string