@mfers/transform-loader

0.3.0-webpack5-rc02 • Public • Published

npm node deps tests coverage chat size

transform-loader

A browserify transformation loader for webpack.

This loader allows use of browserify transforms via a webpack loader.

Getting Started

To begin, you'll need to install transform-loader:

$ npm install transform-loader --save-dev

Note: We're using the coffeeify tranform for these examples.

Then invoke the loader through a require like so:

const thing = require('!transform-loader?coffeeify!widget/thing');

Or add the loader to your webpack config. For example:

// entry.js
import thing from 'widget/thing';
// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.coffee?$/,
        loader: `transform-loader?coffeeify`,
        // options: {...}
      },
    ],
  },
};

And run webpack via your preferred method.

Options

transform

Type: Function Default: undefined

An function that can be used to transform a given file matching the configured loader test. For example:

// entry.js
const thing = require('widget/thing');
// webpack.config.js
const through = require('through2');

module.exports = {
  module: {
    rules: [
      {
        test: /\.ext$/,
        loader: 'transform-loader',
        options: {
          transform: function transform() {
            return through(
              (buffer) => {
                const result = buffer
                  .split('')
                  .map((chunk) =>
                    String.fromCharCode(127 - chunk.charCodeAt(0))
                  );
                return this.queue(result).join('');
              },
              () => this.queue(null)
            );
          },
        },
      },
    ],
  },
};

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @mfers/transform-loader

Weekly Downloads

1

Version

0.3.0-webpack5-rc02

License

MIT

Unpacked Size

8.87 kB

Total Files

5

Last publish

Collaborators

  • lgbot