繁体   English   中英

Webpack 加载器用于“react-markdown” npm 库的.md 文件导入?

[英]Webpack loader for .md file import for “react-markdown” npm library?

当我导入一个.md文件时,它给了我错误,说它无法读取这个特定的.md file syntax ,我知道需要某种加载器来解析导入,但是当我在网上查看时,有一个加载程序称为'markdown-loader' ,仅用于marked npm package。

我正在使用react-markdown package 来读取 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;

控制台错误

这是我的 markdown 内容sample.md

# React & Markdown App

- Benefits of using React... but...
- Write layout in Markdown!

我找不到package,我到处找,你知道装载机吗? 谢谢

尝试使用原始加载器:

module.exports = {
  module: {
    rules: [
      {
        test: /\.md$/,
        use: 'raw-loader'
      }
    ]
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM