Skip to content

jknoxville/remark-mdx-filter-imports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Remark plugin to strip mdx imports matching a given pattern

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published