为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕斯709654 2022-10-21 17:25:09
当我导入一个.md文件时,它给了我一个错误,说它无法读取这个特定.md file syntax的,我知道需要某种加载器来解析导入,但是当我在网上查看时,有一个加载器叫做'markdown-loader'它只用于markednpm 包。我正在使用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!我找不到包,我到处找,你知道装载机吗?谢谢
查看完整描述

1 回答

?
呼唤远方

TA贡献1856条经验 获得超11个赞

尝试使用原始加载器:


module.exports = {

  module: {

    rules: [

      {

        test: /\.md$/,

        use: 'raw-loader'

      }

    ]

  }

}


查看完整回答
反对 回复 2022-10-21
  • 1 回答
  • 0 关注
  • 276 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号