SHIFT + D

Filter by package

  • Overview
  • Ancestor variants
  • Composition
  • Edge
  • Features
  • Linear numeric
  • Logic
  • Prose
  • Source transform
  • SPA links
  • Utilities

Using with Webpack

Updated on August 22, 2024

Baleada Source Transform's Webpack loader can be imported from @baleada/source-transform/webpack, but you won't often need to import it yourself. Usually you'll just specify it as the loader property of a Webpack rule, like so:

//webpack.config.js
const myTransformFunction = require('path/to/myTransformFunction')

module.exports = {
  //...
  module: {
    rules: [
      //...
      {
        test: /\.js$/, // Replace `js` with any file extension
        loader: '@baleada/source-transform/webpack',
        options: { transform: myTransformFunction }
      }
    ]
  }
}

Here's a full breakdown of the options object for the Webpack loader:

Property
Type
Default
Description
transform
Function
({ source }) => source
The transform function, as explained in the Baleada Source Transform overview. Read the rest of this article for additional Webpack-specific guidance.

context and utils in the transform function's first argument

As mentioned in the Baleada Source Transform overview, your transform function's only parameter is an object that includes various properties. Two of these properties—context and utils—have specific values when used with Webpack.

When using Baleada Source Transform with Webpack:

transform function return value

In most cases, you'll probably return a String from your transform function, but to learn more about what else you can return, visit the Webpack docs.

What is Baleada?

Edit doc on GitHub

ON THIS PAGE

Using with Webpackcontext and utils in the transform function's first argumenttransform function return value