Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@saschazar/mdx-extended-loader
Advanced tools
Easily wrap React components around your MDX files
Easily wrap React components around your MDX files
A Webpack loader for mutating your MDX files to export a wrapping React component by default. Easy to extend as well.
It already includes the same functionality as @mdx-js/loader provides, so there is no need to chain it to your Webpack configuration.
yarn add @saschazar/mdx-layout-loader
or
npm install --save @saschazar/mdx-layout-loader
(@mdx-js/react is a dependency you will need when transpiling React to JavaScript code, so be sure to take a look at the peerDependencies
as well.)
It works just as any other Webpack loader, although it is mainly targeted towards transpiling mdx
and md
files.
Given the following project tree, where all the mdx
files should be wrapped in a layout from the layouts
directory:
MyApp
|
├─ pages
| ├ index.jsx
| ├ about.mdx
| ├─ blog
| ├ 2019-12-19_first-blog-post.mdx
|
├─ layouts
├ index.jsx
├ custom.jsx
With two files in the layouts
directory, Webpack should look for mdx
files in the project tree and wrap the most suitable layout around each of them.
The file in the pages/blog
directory includes a date string in its filename, so this information should be parsed as well.
To achieve the goal, Webpack should do the following:
Basically, a simple webpack rule for this use case might look like the following:
{
// other webpack config options
module: {
rules: [
{
test: /\.mdx?$/,
use: [
{
loader: 'babel-loader', // needed for transpiling React code
query: {
cacheDirectory: true
}
},
{
loader: '@saschazar/mdx-extended-loader',
options: {
extensions: ['jsx', 'js'], // the file suffixes the layouts
layoutsDir: 'layouts', // relative to process.cwd()
rehypePlugins: [], // @mdx-js/mdx option
remarkPlugins: [] // @mdx-js/mdx option
}
}
]
},
]
}
});
}
In order to customize the Webpack flow, the following options may be applied to the configuration.
In addition to the options below, the options
object may be extended with the options of the @mdx-js/mdx module.
extensions
array
| mandatory | example:['jsx', 'js']
The file extensions of possible layouts to look for in the layoutsDir
directory
layouts
string
| mandatory | example:layouts
The relative path to the layouts directory in the project's working directory
parseFilename
boolean
| optional | default:true
Whether to attempt to parse the mdx
filename for date
and title
useDefault
boolean
| optional | default:true
Whether to use the index
file in the layouts directory as fallback, when no layout
key was given in the frontmatter
Without next-mdx-enhanced, none of this would have happened, or at least in a very different way.
The main reason why I started this project however, was the fact, that I found next-mdx-enhanced
a little too opinionated and first and foremost too tightly coupled to Next.js.
So I decided to split it into a Webpack-only loader, together with a filename parsing option. Voilà.
Licensed under the MIT license.
Copyright ©️ 2019 - 2020 Sascha Zarhuber
FAQs
Easily wrap React components around your MDX files
The npm package @saschazar/mdx-extended-loader receives a total of 0 weekly downloads. As such, @saschazar/mdx-extended-loader popularity was classified as not popular.
We found that @saschazar/mdx-extended-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.