Gatsby: How to load a file

Created on 13 Sep 2017  ·  1Comment  ·  Source: gatsbyjs/gatsby

Hi, I need to load a html file and then insert it with dangerouslySetInnerHTML.

How can I do it, I tried fs.readFileSync('./form.html'); but the console logs:

This dependency was not found:

* fs in ./src/components/Contact/index.js

To install it, you can run: npm install --save fs

I guess this is because this uses webpack and not just node, but I'm missing some basic concepts here it seems.

Thanks in advance

Most helpful comment

You import it using the raw loader e.g. import htmlFile from 'raw-loader!./form.html'

>All comments

You import it using the raw loader e.g. import htmlFile from 'raw-loader!./form.html'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timbrandin picture timbrandin  ·  3Comments

andykais picture andykais  ·  3Comments

totsteps picture totsteps  ·  3Comments

jimfilippou picture jimfilippou  ·  3Comments

KyleAMathews picture KyleAMathews  ·  3Comments