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.
yarn add -D remark-mdx-filter-imports
See Using plugins in the official documentation.
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';
strippedFilePattern
: By default, the plugin strips local imports (using./
and../
) of files inside anyprivate/
directory (at any nested level). Overriding this with a regex lets you customise which import targets are stripped.
After installing dependencies with yarn
, the tests can be run with: yarn test