I am trying to incrementally build a React site with the content written in Markdown.
I am stuck so far as I am trying to import a single Markdown file with Frontmatter to render.
I have tried front-matter-loader and raw-loader; both throw errors:
/pages/home.md: Invalid left-hand side in prefix operation (1:2)
1 | ---
| ^
2 | title: This is the home page
3 | ---
Here is my simple JavaScript test:
import home from '../pages/home.md';
console.log('testing');
console.log(home);
Here are my loaders in the webpack config:
...
module: {
rules: [
{
test: /\.(js)$/,
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
cacheDirectory: '.babel_cache'
}
}
},
{
test: /\.md$/,
use: 'raw-loader'
}
]
},
...
What I expected from using raw-loader was a string, which I could then pass to front-matter, extract, and then render HTML with marked. However, I obviously cannot seem to require/import the file properly. My next tests will be to remove the webpack loaders altogether and try to use node's fs to read the file. I wondered if anyone would be able to help me spot any error here.
I keep thinking, the front-matter-loader is not a complicated file at all (view here), and there's no reason why it shouldn't load the file.
Thanks for any insight.