@bundles/bundles-filters

0.2.1 • Public • Published

Bundles Filters Bundler

NPM version NPM downloads per month Travis branch Codacy code grade Codacy coverage Coverage Status JavaScript Style Guide code style: prettier semantic release Commitizen friendly License Greenkeeper badge

This is a bundler plugin for use with Bundles which filters files for use with other bundlers.

Environment support

Node CLI ES Module Browser UMD
x x

Install

Make sure Bundles is installed.

npm install @bundles/bundles-filters -D

Usage

See configuring Bundles for details on configuring Bundles and bundlers.

filters

filters is the only configuration option. It allows you to create one or more filters, each which do one of the following:

  1. Permanently remove specified output files from bundle.output.
  2. Run a series of bundlers on a temporarily filtered subset of output files from bundle.output. NOTE: This does not remove anything from bundle.output, the filter only applies temporarily while the configured bundlers run.

filter

Properties:

  • pattern {String|String[]|Function} (required) Use glob pattern(s) to test against each input source path. If the path matches, it will be included in the filter. Or you may pass a custom Function for more flexibility. Custom functions receive file, bundle, and micromatch as parameters, and must return a Boolean to tell Bundles if a file should be added to the filter. For example:
    function myCustomFilter(file, { bundle, micromatch }) {
      // Return `true` to add to filter.
      return true;
    }
  • type {string} Default: 'some' micromatch is used to test filter patterns. By default, the micromatch.some() method is used to test. You may tweak the behavior to your liking by passing 'every', 'any', 'all', 'not', or 'contains' to use the corresponding micromatch method.
  • options {Object} Options passed directly to micromatch.
  • reverse {Boolean} When true, files that do NOT match filter.pattern will be added to the filter.
  • bundlers {Object[]} When this property exists, files that match the filter will be run through these bundlers. This is useful to run certain bundlers only on a subset of a larger grouping of files. The bundlers property can be configured exactly like bundlers in bundle.bundlers. See configuring Bundles for more details.

Example:

const bundle = {
  input: [...],
  bundlers: [
    {
      run: require('@bundles/bundles-filters'),
      filters: [
        {
          // These files will be removed permanently.
          pattern: ['!*.yaml'],
        },
        {
          // All other filters will run their matching subset of files through
          // the configured bundlers, after which the original `bundle.output`
          // (minus the removed files) is restored.
          pattern: ['{one,two,three}.md'],
          bundlers: [markdown, footer],
        },
        {
          // Pattern can be a Function.
          pattern: (file, { bundle, micromatch }) => path.extname(file.source.path) === '.css',
          bundlers: [css],
        },
        {
          pattern: ['*.{css,js}', '!three.js'],
          bundlers: [banner, footer],
        },
        {
          pattern: '*.json',
          bundlers: [json],
        },
      ],
    },
  ];
}

Package Sidebar

Install

npm i @bundles/bundles-filters

Weekly Downloads

1

Version

0.2.1

License

MIT

Unpacked Size

10.8 kB

Total Files

4

Last publish

Collaborators

  • thezimmee