falafel-loader

Run a falafel AST transform as a webpack-loader

Usage no npm install needed!

<script type="module">
  import falafelLoader from 'https://cdn.skypack.dev/falafel-loader';
</script>

README

falafel-loader

Loader to run falafel AST transforms.

Installation

npm i -D falafel-loader

Usage

This example fixes an IE angular bug.

Add it into the pipeline for a js file & add falafel config:

modules: {
  falafel: function (node) {
    if (node.type === 'FunctionExpression' && node.id && node.id.name === 'interpolateFnWatchAction') {
      var expr = node && node.body && node.body.body && node.body.body[0];

      if (expr && expr.source() === 'node[0].nodeValue = value;') {
        expr.update('if (!node[0].nodeValue) { return; } ' + expr.source());
      }
    }
  },
  ...
  loaders: [
    ...
      {
        test: /angular\.js$/,
        loader: 'falafel-loader'
      }
    ...
  ]
  ...
}

This will rewrite the interpolateFnWatchAction with the necessary null check. You can implement any falafel function that you want, however.

TODO

  • Allow multiple falafel pipelines.