transform loader for webpack
JavaScript
Switch branches/tags
Clone or download
shellscape and d3viant0ne refactor(defaults): update to latest webpack-defaults (#31)
BREAKING CHANGE: Enforces `engines` of `"node": ">=6.9.0 < 7.0.0 || >= 8.9.0`
Latest commit 9675894 Apr 30, 2018
Permalink
Failed to load latest commit information.
.circleci refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
.github refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
src refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
test refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
.babelrc refactor: webpack 4.x compatibility (#30) Apr 6, 2018
.editorconfig refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
.eslintignore refactor: webpack 4.x compatibility (#30) Apr 6, 2018
.eslintrc refactor: webpack 4.x compatibility (#30) Apr 6, 2018
.eslintrc.js refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
.gitattributes refactor: webpack 4.x compatibility (#30) Apr 6, 2018
.gitignore refactor: webpack 4.x compatibility (#30) Apr 6, 2018
.prettierrc refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
CHANGELOG.md refactor: webpack 4.x compatibility (#30) Apr 6, 2018
LICENSE refactor: webpack 4.x compatibility (#30) Apr 6, 2018
README.md refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
appveyor.yml refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
codecov.yml refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
commitlint.config.js refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
package-lock.json refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018
package.json refactor(defaults): update to latest webpack-defaults (#31) Apr 30, 2018

README.md

npm node deps tests chat

transform-loader

A browserify transformation loader for webpack.

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

Requirements

This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.

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.

QueryString Options

When using the loader via a require query string you may specify one of two types; a loader name, or a function index.

Type: String

The name of the browserify transform you wish to use.

Note: You must install the correct transform manually. Webpack nor this loader will do that for you.

Type: Number

The index of a function contained within options.transforms which to use to transform the target file(s).

Options

transforms

Type: Array[Function] Default: undefined

An array of functions 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$/,
        // NOTE: we've specified an index of 0, which will use the `transform`
        //       function in `transforms` below.
        loader: 'transform-loader?0',
        options: {
          transforms: [
            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)
              );
            }
          ]
        }
      }
    ]
  }
}

License

MIT