remark-mdx-filter-imports

0.1.3 • Public • Published

remark-mdx-filter-imports

npm version

Strip mdx imports that match a given pattern. Sometimes you want to build subsets of your code base, perhaps with some private files stripped.

This plugin allows you to define a file pattern for matching files, and then remove any imports of those files, allowing the build to succeed.

Installation

yarn add -D remark-mdx-filter-imports

Setup

See Using plugins in the official documentation.

Usage

const {createCompiler} = require('@mdx-js/mdx');
const filterImports = require('remark-mdx-filter-impoorts');

const config = {
  strippedFilePattern: /\/my-private-dir\//
};
createCompiler({remarkPlugins: [[filterImports, config]]})
  .parse(...);

Transforms:

import a from 'b';
import c from './private/d';

into:

import a from 'b';

Options

  • strippedFilePattern: By default, the plugin strips local imports (using ./ and ../) of files inside any private/ directory (at any nested level). Overriding this with a regex lets you customise which import targets are stripped.

Testing

After installing dependencies with yarn, the tests can be run with: yarn test

Package Sidebar

Install

npm i remark-mdx-filter-imports

Weekly Downloads

2,527

Version

0.1.3

License

MIT

Unpacked Size

4.64 kB

Total Files

4

Last publish

Collaborators

  • fb
  • jknoxville