当我导入一个.md文件时,它给我一个错误,说它无法读取这个特定的.md file syntax,我知道需要某种类型的加载器来解析导入,但当我在网上查看时,有一个名为'markdown-loader'的加载器,它只适用于marked npm包。
我正在使用react-markdown包读取md文件
/* eslint-disable react/prefer-stateless-function */
import React, { Component } from 'react';
import ReactMarkdown from 'react-markdown';
import AppMarkdown from './posts/sample.md';
// import PropTypes from 'prop-types';
class CardDetails extends Component {
constructor() {
super();
this.state = { markdown: '' };
}
componentDidMount() {
// Get the contents from the Markdown file and put them in the React state, so we can reference it in render() below.
fetch(AppMarkdown)
.then(res => res.text())
.then(text => this.setState({ markdown: text }));
}
render() {
const { markdown } = this.state;
return <ReactMarkdown source={markdown} />;
}
}
CardDetails.propTypes = {};
export default CardDetails;

下面是我的降价内容sample.md
# React & Markdown App
- Benefits of using React... but...
- Write layout in Markdown!我找不到包裹,我到处找,你知道装载机吗?谢谢你
发布于 2020-06-29 22:10:33
尝试使用raw-loader:
module.exports = {
module: {
rules: [
{
test: /\.md$/,
use: 'raw-loader'
}
]
}
}https://stackoverflow.com/questions/62639858
复制相似问题