@bundles/bundles-filters
v0.2.1
Published
A bundler plugin for Bundles which allows you to create a series of dynamic filters to run through other bundlers.
Downloads
15
Maintainers
Readme
Bundles Filters Bundler
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 filter
s, each which do one of the following:
- Permanently remove specified output files from
bundle.output
. - Run a series of bundlers on a temporarily filtered subset of output files from
bundle.output
. NOTE: This does not remove anything frombundle.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 receivefile
,bundle
, andmicromatch
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, themicromatch.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 matchfilter.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. Thebundlers
property can be configured exactly like bundlers inbundle.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],
},
],
},
];
}