I am trying to get load a markdown file to be loaded on build. I have setup a create-react-app that uses Typescript and using a material_ui blog theme.
import ReactMarkdown from 'markdown-to-jsx';
import post1 from './blog-post.1.md';
export default function Main(props: MainProps) {
const classes = useStyles();
const { posts, title } = props;
return (
<Grid item xs={12} md={8}>
<Typography variant="h6" gutterBottom>
{title}
</Typography>
<Divider />
{posts.map((post) => (
<Markdown className={classes.markdown} key={post.substring(0, 40)}>
{post}
</Markdown>
))}
</Grid>
);
}
If a post is assigned to be markdown, it will render correctly: const post = '# Sample blog post #### April 1, 2020 by [Olivier](/)'
So the issue is that .md file is not loading into the variable.
When npm start
is run, the html displays: /static/media/blog-post.1.09e7833f.md
Why would this be and what is that number: 09e7833f in the filepath?
I would ideally like to load the file in during build time so that it can be served more quickly on somewhere like Netlify. I do not want to use an asynchronous fetch like this answer suggests.
I assume I would have to create a webpack loader? The problem with this is that create-react-app has webpack.config.js
in the node_modules
which means customising it would be overwritten during a new build. I don't think using raw-loader helps if I can't configure it.
I've also tried import post1 from 'raw-loader!./blog-post.1.md';
as suggested here but Typescript doesn't know what to do with that.
Any suggestions would be helpful.